ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-08-05 05:53:33
Exec Total Coverage
Lines: 2776 8330 33.3%
Functions: 76 290 26.2%
Branches: 2402 7193 33.4%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "zq/zquestdat.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "md5.h"
34 #include "zc/zc_custom.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57 extern FFScript FFCore;
58
59 extern ZModule zcm;
60 extern zcmodule moduledata;
61 extern uint8_t ViewLayer3BG, ViewLayer2BG;
62 extern int32_t LayerDitherBG, LayerDitherSz;
63 extern bool NoHighlightLayer0;
64
65 using std::string;
66 using std::pair;
67 #define EPSILON 0.01 // Define your own tolerance
68 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 9 zmap Map;
81 int32_t prv_mode=0;
82 int16_t ffposx[MAXFFCS];
83 int16_t ffposy[MAXFFCS];
84 int32_t ffprvx[MAXFFCS];
85 int32_t ffprvy[MAXFFCS];
86 void init_ffpos()
87 {
88 for (word q = 0; q < MAXFFCS; ++q)
89 {
90 ffposx[q] = -1000;
91 ffposy[q] = -1000;
92 ffprvx[q] = -10000000;
93 ffprvy[q] = -10000000;
94 }
95 }
96
97 bool save_warn=true;
98
99 int32_t COMBOPOS(int32_t x, int32_t y)
100 {
101 return (((y) & 0xF0) + ((x) >> 4));
102 }
103 int32_t COMBOPOS_B(int32_t x, int32_t y)
104 {
105 if(unsigned(x) >= 256 || unsigned(y) >= 176)
106 return -1;
107 return COMBOPOS(x,y);
108 }
109 int32_t COMBOX(int32_t pos)
110 {
111 return ((pos) % 16 * 16);
112 }
113 int32_t COMBOY(int32_t pos)
114 {
115 return ((pos) & 0xF0);
116 }
117
118 void reset_dmap(int32_t index)
119 {
120 bound(index,0,MAXDMAPS-1);
121 DMaps[index].clear();
122 DMaps[index].title = "";
123 sprintf(DMaps[index].intro, " ");
124 }
125
126 void reset_dmaps()
127 {
128 for(int32_t i=0; i<MAXDMAPS; i++)
129 reset_dmap(i);
130 }
131
132 void truncate_dmap_title(std::string& title)
133 {
134 title.resize(21, ' ');
135 }
136
137 mapscr* zmap::get_prvscr()
138 {
139 return &prvscr;
140 }
141
142
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
143 {
144 18 can_paste=false;
145 18 prv_cmbcycle=0;
146 18 prv_advance=0;
147 18 prv_freeze=0;
148 18 copyffc=-1;
149
150 18 memset(scrpos, 0, sizeof(scrpos));
151 18 screens=NULL;
152 18 prv_time=0;
153 18 prv_scr=0;
154 18 prv_map=0;
155 18 copyscr=0;
156 18 currscr=0;
157 18 copymap=0;
158 18 currmap=0;
159 18 layer_target_map = 0;
160 18 layer_target_scr = 0;
161 18 layer_target_multiple = 0;
162
163 18 }
164 18 zmap::~zmap()
165 {
166 18 }
167
168 9 void zmap::clear()
169 {
170
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
171 9 }
172 void zmap::force_refr_pointer()
173 {
174 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
175 screens = nullptr;
176 else screens = &TheMaps[currmap*MAPSCRS];
177 }
178 bool zmap::CanUndo()
179 {
180 return undo_stack.size() > 0;
181 }
182 bool zmap::CanRedo()
183 {
184 return redo_stack.size() > 0;
185 }
186 bool zmap::CanPaste()
187 {
188 return can_paste;
189 }
190 int32_t zmap::CopyScr()
191 {
192 return (copymap<<8)+copyscr;
193 }
194 int32_t zmap::getCopyFFC()
195 {
196 return copyffc;
197 }
198 set_ffc_command::data_t zmap::getCopyFFCData()
199 {
200 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
201 }
202 29 int32_t zmap::getMapCount()
203 {
204 29 return map_count;
205 }
206 int32_t zmap::getLayerTargetMap()
207 {
208 return layer_target_map;
209 }
210 int32_t zmap::getLayerTargetScr()
211 {
212 return layer_target_scr;
213 }
214 int32_t zmap::getLayerTargetMultiple()
215 {
216 return layer_target_multiple;
217 }
218 bool zmap::isDungeon(int32_t scr)
219 {
220 for(int32_t i=0; i<4; i++)
221 {
222 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
223 {
224 return false;
225 }
226 }
227
228 return true;
229 }
230
231 bool zmap::clearall(bool validate)
232 {
233 Color=0;
234 char tbuf[10];
235
236 if((header.templatepath[0]!=0)&&validate)
237 {
238 if(!valid_zqt(header.templatepath))
239 {
240 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
241 return false;
242 }
243 }
244
245 for(int32_t i=0; i<map_count; i++)
246 {
247 setCurrMap(i);
248 sprintf(tbuf, "%d", i);
249 clearmap(true);
250 }
251
252 setCurrMap(0);
253 return true;
254 }
255
256 bool zmap::reset_templates(bool validate)
257 {
258 //why are we doing this?
259 if(colordata==NULL)
260 {
261 return false;
262 }
263
264 char *deletefilename=(char *)malloc(1);
265 ASSERT(deletefilename);
266 deletefilename[0]=0;
267
268 //int32_t ret;
269 word version, build, dummy, sversion=0;
270 byte dummyc;
271 word dummyw;
272 //int32_t section_size;
273 word temp_map_count;
274 mapscr temp_mapscr;
275 PACKFILE *f=NULL;
276
277 // setPackfilePassword(datapwd);
278 f=open_quest_template(&header, deletefilename, validate);
279 get_version_and_build(f, &version, &build);
280
281 if(!find_section(f, ID_MAPS))
282 {
283 // setPackfilePassword(NULL);
284 return false;
285 }
286
287 //section version info
288 if(!p_igetw(&sversion,f))
289 {
290 return false;
291 }
292
293 if(!p_igetw(&dummy,f))
294 {
295 return false;
296 }
297
298 //section size
299 dword dummy_size;
300 if(!p_igetl(&dummy_size,f))
301 {
302 return false;
303 }
304
305 //finally... section data
306 if(!p_igetw(&temp_map_count,f))
307 {
308 return false;
309 }
310
311 if(version>12)
312 {
313 if(!p_getc(&dummyc,f))
314 return qe_invalid;
315
316 if(!p_getc(&dummyc,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_igetw(&dummyw,f))
323 return qe_invalid;
324
325 if(!p_igetw(&dummyw,f))
326 return qe_invalid;
327
328 if(!p_igetw(&dummyw,f))
329 return qe_invalid;
330
331 if(!p_igetw(&dummyw,f))
332 return qe_invalid;
333
334 if(!p_igetw(&dummyw,f))
335 return qe_invalid;
336
337 if(!p_igetw(&dummyw,f))
338 return qe_invalid;
339
340 if(!p_igetw(&dummyw,f))
341 return qe_invalid;
342
343 if(!p_igetw(&dummyw,f))
344 return qe_invalid;
345
346 if(!p_igetw(&dummyw,f))
347 return qe_invalid;
348
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354 }
355
356 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
357 {
358 readmapscreen(f, &header, &temp_mapscr, sversion);
359 }
360
361 readmapscreen(f, &header, &TheMaps[128], sversion);
362 readmapscreen(f, &header, &TheMaps[129], sversion);
363
364 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
365 {
366 readmapscreen(f, &header, &temp_mapscr, sversion);
367 }
368
369 if(version>12)
370 {
371 if(!p_getc(&dummyc,f))
372 return qe_invalid;
373
374 if(!p_getc(&dummyc,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_igetw(&dummyw,f))
381 return qe_invalid;
382
383 if(!p_igetw(&dummyw,f))
384 return qe_invalid;
385
386 if(!p_igetw(&dummyw,f))
387 return qe_invalid;
388
389 if(!p_igetw(&dummyw,f))
390 return qe_invalid;
391
392 if(!p_igetw(&dummyw,f))
393 return qe_invalid;
394
395 if(!p_igetw(&dummyw,f))
396 return qe_invalid;
397
398 if(!p_igetw(&dummyw,f))
399 return qe_invalid;
400
401 if(!p_igetw(&dummyw,f))
402 return qe_invalid;
403
404 if(!p_igetw(&dummyw,f))
405 return qe_invalid;
406
407 if(!p_getc(&dummyc,f))
408 return qe_invalid;
409
410 if(!p_getc(&dummyc,f))
411 return qe_invalid;
412 }
413
414 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
415 {
416 readmapscreen(f, &header, &temp_mapscr, sversion);
417 }
418
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
420 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
421
422 pack_fclose(f);
423 clear_quest_tmpfile();
424
425 if(deletefilename[0]==0)
426 {
427 delete_file(deletefilename);
428 }
429
430
431 return true;
432 }
433
434 bool zmap::clearmap(bool newquest)
435 {
436 if(currmap<map_count)
437 {
438 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
439 {
440 clearscr(i);
441 }
442
443 setCurrScr(0);
444
445 if(newquest)
446 {
447 if(!reset_templates(false))
448 {
449 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
450 }
451 }
452 }
453
454 return true;
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+currscr;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::AbsoluteScr(int32_t scr)
466 {
467 if(unsigned(scr) >= MAPSCRS*getMapCount())
468 return nullptr;
469 return &TheMaps[scr];
470 }
471 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
472 {
473 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
474 return nullptr;
475 return AbsoluteScr((map*MAPSCRS)+scr);
476 }
477 void zmap::set_prvscr(int32_t map, int32_t scr)
478 {
479 prvscr=TheMaps[(map*MAPSCRS)+scr];
480
481 for(int32_t i=0; i<6; i++)
482 {
483 if(prvscr.layermap[i]>0)
484 {
485 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
486 }
487 else
488 prvlayers[i].valid = 0;
489 }
490
491 prv_map=map;
492 prv_scr=scr;
493 }
494 71 int32_t zmap::getCurrMap()
495 {
496 71 return currmap;
497 }
498 bool zmap::isDark()
499 {
500 return (screens[currscr].flags&fDARK)!=0;
501 }
502
503 void zmap::setCurrentView(int32_t map, int32_t scr)
504 {
505 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
506 if (map != Map.getCurrMap()) Map.setCurrMap(map);
507 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
508 if (change_view)
509 {
510 refresh(rALL);
511 rebuild_trans_table();
512 }
513 }
514
515 9 void zmap::setCurrMap(int32_t index)
516 {
517 9 int32_t oldmap=currmap;
518 9 optional<int> oldcolor;
519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
520 oldcolor = getcolor();
521 9 scrpos[currmap]=currscr;
522 9 currmap=bound(index,0,map_count);
523 9 screens=&TheMaps[currmap*MAPSCRS];
524
525 9 currscr=scrpos[currmap];
526 9 int newcolor = getcolor();
527 9 loadlvlpal(newcolor);
528
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
529 9 rebuild_trans_table();
530
531 9 reset_combo_animations2();
532 9 mmap_mark_dirty();
533 9 }
534
535 17 int32_t zmap::getCurrScr()
536 {
537 17 return currscr;
538 }
539 9 void zmap::setCurrScr(int32_t scr)
540 {
541
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
542
543 8 int32_t oldscr=currscr;
544 8 int32_t oldcolor=getcolor();
545
546
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
547 {
548 2 oldcolor=-1;
549 2 }
550
551 8 currscr=bound(scr,0,MAPSCRS-1);
552 8 int32_t newcolor=getcolor();
553 8 loadlvlpal(newcolor);
554
555 //setcolor(newcolor);
556
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
557 {
558 newcolor=-1;
559 }
560
561
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
562 {
563 7 rebuild_trans_table();
564 7 }
565
566 8 reset_combo_animations2();
567 8 setlayertarget();
568 8 mmap_mark_dirty();
569 9 }
570
571 8 void zmap::setlayertarget()
572 {
573 8 layer_target_map = 0;
574 8 layer_target_multiple = 0;
575
576
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
577 {
578
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
579 {
580 2856 int32_t i=(m*MAPSCRS+s);
581 2856 mapscr *ts=&TheMaps[i];
582
583 // Search through each layer
584
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
585 {
586
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
587 {
588 if(layer_target_map > 0)
589 {
590 layer_target_multiple += 1;
591 continue;
592 }
593
594 layer_target_map = m+1;
595 layer_target_scr = s;
596 }
597 17136 }
598 2856 }
599 21 }
600 8 }
601
602 void zmap::setcolor(int32_t c)
603 {
604 screens[currscr].valid |= mVALID;
605 screens[currscr].color = c;
606
607 if(Color!=c)
608 {
609 Color = c;
610 loadlvlpal(c);
611 rebuild_trans_table();
612 }
613
614 mmap_mark_dirty();
615 }
616
617 25 int32_t zmap::getcolor()
618 {
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
620 {
621 return prvscr.color;
622 }
623
624 25 return screens[currscr].color;
625 25 }
626
627 void zmap::resetflags()
628 {
629 byte *di=&(screens[currscr].valid);
630
631 for(int32_t i=1; i<48; i++)
632 {
633 *(di+i)=0;
634 }
635 }
636
637 word zmap::tcmbdat(int32_t pos)
638 {
639 return screens[TEMPLATE].data[pos];
640 }
641
642 word zmap::tcmbcset(int32_t pos)
643 {
644 return screens[TEMPLATE].cset[pos];
645 }
646
647 int32_t zmap::tcmbflag(int32_t pos)
648 {
649 return screens[TEMPLATE].sflag[pos];
650 }
651
652 word zmap::tcmbdat2(int32_t pos)
653 {
654 return screens[TEMPLATE2].data[pos];
655 }
656
657 word zmap::tcmbcset2(int32_t pos)
658 {
659 return screens[TEMPLATE2].cset[pos];
660 }
661
662 int32_t zmap::tcmbflag2(int32_t pos)
663 {
664 return screens[TEMPLATE2].sflag[pos];
665 }
666
667 void zmap::TemplateAll()
668 {
669 StartListCommand();
670 for(int32_t i=0; i<128; i++)
671 {
672 if((screens[i].valid&mVALID) && isDungeon(i))
673 DoTemplateCommand(-1, i, currscr);
674 }
675 FinishListCommand();
676 }
677
678 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
679 {
680 if(scr==TEMPLATE)
681 return;
682
683 if(!(screens[scr].valid&mVALID))
684 screens[scr].color=Color;
685
686 screens[scr].valid|=mVALID;
687
688 for(int32_t i=0; i<32; i++)
689 {
690 screens[scr].data[i]=screens[TEMPLATE].data[i];
691 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
692 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
693 }
694
695 for(int32_t i=144; i<176; i++)
696 {
697 screens[scr].data[i]=screens[TEMPLATE].data[i];
698 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
699 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
700 }
701
702 for(int32_t y=2; y<=9; y++)
703 {
704 int32_t j=y<<4;
705 screens[scr].data[j]=screens[TEMPLATE].data[j];
706 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
707 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
708 ++j;
709 screens[scr].data[j]=screens[TEMPLATE].data[j];
710 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
711 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
712 ++j;
713 j+=12;
714 screens[scr].data[j]=screens[TEMPLATE].data[j];
715 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
716 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
717 ++j;
718 screens[scr].data[j]=screens[TEMPLATE].data[j];
719 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
720
721 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
722 ++j;
723 }
724
725 if(floorcombo!=-1)
726 {
727 for(int32_t y=2; y<9; y++)
728 for(int32_t x=2; x<14; x++)
729 {
730 int32_t i=(y<<4)+x;
731 screens[scr].data[i] = floorcombo;
732 screens[scr].cset[i] = floorcset;
733 }
734 }
735
736 for(int32_t i=0; i<4; i++)
737 putdoor(scr,i,screens[scr].door[i]);
738 }
739
740
741 void zmap::clearscr(int32_t scr)
742 {
743 screens[scr].zero_memory();
744 screens[scr].valid=mVERSION;
745 for(int q = 0; q < 6; ++q)
746 {
747 auto layer = map_autolayers[currmap*6+q];
748 screens[scr].layermap[q] = layer;
749 screens[scr].layerscreen[q] = layer ? scr : 0;
750 }
751 mmap_mark_dirty();
752 }
753
754 const char *loaderror[] =
755 {
756
757 "OK","File not found","Incomplete data",
758 "Invalid version","Invalid file"
759
760 };
761
762 int32_t zmap::load(const char *path)
763 {
764 PACKFILE *f=pack_fopen_password(path,F_READ, "");
765
766 if(!f)
767 return 1;
768
769
770 int16_t version;
771 byte build;
772
773 //get the version
774 if(!p_igetw(&version,f))
775 {
776 goto file_error;
777 }
778
779 //get the build
780 if(!p_getc(&build,f))
781 {
782 goto file_error;
783 }
784
785 for(int32_t i=0; i<MAPSCRS; i++)
786 {
787 mapscr tmpimportscr;
788 tmpimportscr.zero_memory();
789 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
790 {
791 al_trace("failed zmap::load\n");
792 goto file_error;
793 }
794
795 switch(ImportMapBias)
796 {
797 case 0:
798 *(screens+i) = tmpimportscr;
799 break;
800
801 case 1:
802 if(!(screens[i].valid&mVALID))
803 {
804 *(screens+i) = tmpimportscr;
805 }
806 break;
807
808 case 2:
809 if(tmpimportscr.valid&mVALID)
810 {
811 *(screens+i) = tmpimportscr;
812 }
813 break;
814 }
815 }
816
817
818 pack_fclose(f);
819
820 setCurrScr(0);
821 mmap_mark_dirty();
822 return 0;
823
824 file_error:
825 pack_fclose(f);
826 clearmap(false);
827 return 2;
828 }
829
830 int32_t zmap::save(const char *path)
831 {
832 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
833
834 if(!f)
835 return 1;
836
837 if(!p_iputw(V_MAPS,f))
838 {
839 pack_fclose(f);
840 return 3;
841 }
842
843 // This was the "build number", but that's totally useless here. Keep this junk byte
844 // so as not to totally break exports between ZC versions.
845 if(!p_putc(0,f))
846 {
847 pack_fclose(f);
848 return 3;
849 }
850
851 for(int32_t i=0; i<MAPSCRS; i++)
852 {
853 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
854 {
855 pack_fclose(f);
856 return 2;
857 }
858 }
859
860 pack_fclose(f);
861 return 0;
862 }
863
864
865 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
866 {
867 // Hookshots can be blocked by solid combos on all 3 ground layers.
868 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
869
870 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
871 return true;
872 if (c->walk&(1<<i))
873 return false;
874
875 for(int32_t k=0; k<2; k++)
876 {
877 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
878
879 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
880 {
881 return false;
882 }
883 }
884
885 return true;
886 }
887
888 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
889 {
890 // Hookshots can be blocked by solid combos on all 3 ground layers.
891 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
892
893 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
894 return true;
895 if (c->walk&(1<<i))
896 return false;
897
898 for(int32_t k=0; k<2; k++)
899 {
900 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
901
902 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
903 {
904 return false;
905 }
906 }
907
908 return true;
909 }
910
911 bool zmap::isstepable(int32_t combo)
912 {
913 // This is kind of odd but it's true to the engine (see maps.cpp)
914 return (combo_class_buf[combobuf[combo].type].ladder_pass);
915 }
916
917 // Returns the letter of the warp combo.
918 int32_t zmap::warpindex(int32_t combo)
919 {
920 switch(combobuf[combo].type)
921 {
922 case cCAVE:
923 case cPIT:
924 case cSTAIR:
925 case cCAVE2:
926 case cSWIMWARP:
927 case cDIVEWARP:
928 case cSWARPA:
929 return 0;
930
931 case cCAVEB:
932 case cPITB:
933 case cSTAIRB:
934 case cCAVE2B:
935 case cSWIMWARPB:
936 case cDIVEWARPB:
937 case cSWARPB:
938 return 1;
939
940 case cCAVEC:
941 case cPITC:
942 case cSTAIRC:
943 case cCAVE2C:
944 case cSWIMWARPC:
945 case cDIVEWARPC:
946 case cSWARPC:
947 return 2;
948
949 case cCAVED:
950 case cPITD:
951 case cSTAIRD:
952 case cCAVE2D:
953 case cSWIMWARPD:
954 case cDIVEWARPD:
955 case cSWARPD:
956 return 3;
957
958 case cPITR:
959 case cSTAIRR:
960 case cSWARPR:
961 return 4;
962 }
963
964 return -1;
965
966 }
967
968 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
969 {
970 if(top)
971 line(dest,x,y,x+15,y,c);
972 rectfill(dest,x,y,x+3,y+15,c);
973 rectfill(dest,x+12,y,x+15,y+15,c);
974 rectfill(dest,x+4,y+2,x+11,y+5,c);
975 rectfill(dest,x+4,y+10,x+11,y+13,c);
976 }
977
978 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
979 {
980 line(dest,x,y,x+15,y,c);
981 }
982
983 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
984 {
985 int32_t cx = COMBOX(pos);
986 int32_t cy = COMBOY(pos);
987
988 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
989
990 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
991
992 int32_t bridgedetected = 0;
993
994 for(int32_t i=0; i<4; i++)
995 {
996 int32_t tx=((i&2)<<2)+x;
997 int32_t ty=((i&1)<<3)+y;
998 int32_t tx2=((i&2)<<2)+cx;
999 int32_t ty2=((i&1)<<3)+cy;
1000 for (int32_t m = layer; m <= 1; m++)
1001 {
1002 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1003 {
1004 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1005 {
1006 bridgedetected |= (1<<i);
1007 }
1008 }
1009 else
1010 {
1011 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1012 {
1013 bridgedetected |= (1<<i);
1014 }
1015 }
1016 }
1017 if (bridgedetected & (1<<i))
1018 {
1019 if (i >= 3) break;
1020 else continue;
1021 }
1022 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1023 {
1024 for(int32_t k=0; k<8; k+=2)
1025 for(int32_t j=0; j<8; j+=2)
1026 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1027 }
1028 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1029 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1030
1031 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1032 {
1033 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1034 {
1035 for(int32_t k=0; k<8; k+=2)
1036 for(int32_t j=0; j<8; j+=2)
1037 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1038 }
1039 else
1040 {
1041 int32_t color = COLOR_SOLID;
1042
1043 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1044 color=vc(6);
1045 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1046 color=vc(7);
1047
1048 rectfill(dest,tx,ty,tx+7,ty+7,color);
1049 }
1050 }
1051 }
1052
1053 bridgedetected = 0;
1054 for(int32_t i=0; i<4; i++)
1055 {
1056 int32_t tx2=((i&2)<<2)+cx;
1057 int32_t ty2=((i&1)<<3)+cy;
1058 for (int32_t m = 0; m <= 1; m++)
1059 {
1060 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1061 {
1062 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1063 {
1064 bridgedetected |= (1<<i);
1065 }
1066 }
1067 else
1068 {
1069 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1070 {
1071 bridgedetected |= (1<<i);
1072 }
1073 }
1074 }
1075 }
1076
1077 // Draw damage combos
1078 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1079 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1080 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1081 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1082 || combo_class_buf[c1.type].modify_hp_amount
1083 || combo_class_buf[c2.type].modify_hp_amount;
1084
1085 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1086
1087 if(dmg)
1088 {
1089 if (bridgedetected <= 0)
1090 {
1091 for(int32_t k=0; k<16; k+=2)
1092 for(int32_t j=0; j<16; j+=2)
1093 if(((k+j)/2)%2)
1094 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1095 }
1096 else
1097 {
1098 for(int32_t i=0; i<4; i++)
1099 {
1100 if (!(bridgedetected & (1<<i)))
1101 {
1102 int32_t tx=((i&2)<<2)+x;
1103 int32_t ty=((i&1)<<3)+y;
1104 for(int32_t k=0; k<8; k+=2)
1105 for(int32_t j=0; j<8; j+=2)
1106 if(((k+j)/2)%2)
1107 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1108 }
1109 }
1110 }
1111 }
1112
1113 if(c.type == cSLOPE)
1114 {
1115 slope_info s(c, x, y);
1116 s.draw(dest, 0, 0, COLOR_SLOPE);
1117 }
1118 auto fl0 = MAPFLAG2(-1,cx,cy);
1119 auto fl1 = MAPFLAG2(0,cx,cy);
1120 auto fl2 = MAPFLAG2(1,cx,cy);
1121 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1122 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1123 {
1124 bool top = false;
1125 if(cy)
1126 {
1127 top = true;
1128 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1131 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1133 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1134 {
1135 top = false;
1136 }
1137 }
1138 draw_ladder(dest,x,y,COLOR_LADDER,top);
1139 }
1140 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1141 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1142 {
1143 draw_platform(dest,x,y,COLOR_LADDER);
1144 }
1145 }
1146
1147 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1148 {
1149 int32_t cx = COMBOX(pos);
1150 int32_t cy = COMBOY(pos);
1151
1152 if (screen < 0) return;
1153 if (map < 0) return;
1154
1155 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1156
1157 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1158
1159 int32_t bridgedetected = 0;
1160 for(int32_t i=0; i<4; i++)
1161 {
1162 int32_t tx=((i&2)<<2)+x;
1163 int32_t ty=((i&1)<<3)+y;
1164 int32_t tx2=((i&2)<<2)+cx;
1165 int32_t ty2=((i&1)<<3)+cy;
1166 for (int32_t m = layer; m <= 1; m++)
1167 {
1168 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1169 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1170 {
1171 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1172 {
1173 bridgedetected |= (1<<i);
1174 }
1175 }
1176 else
1177 {
1178 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1179 {
1180 bridgedetected |= (1<<i);
1181 }
1182 }
1183 }
1184 if (bridgedetected & (1<<i))
1185 {
1186 continue;
1187 }
1188 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1189 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1190
1191
1192 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1193 {
1194 for(int32_t k=0; k<8; k+=2)
1195 for(int32_t j=0; j<8; j+=2)
1196 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1197 }
1198 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1199 {
1200 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1201 {
1202 for(int32_t k=0; k<8; k+=2)
1203 for(int32_t j=0; j<8; j+=2)
1204 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1205 }
1206 else
1207 {
1208 int32_t color = COLOR_SOLID;
1209
1210 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1211 color=vc(6);
1212 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1213 color=vc(7);
1214
1215 rectfill(dest,tx,ty,tx+7,ty+7,color);
1216 }
1217 }
1218 }
1219
1220 bridgedetected = 0;
1221 for(int32_t i=0; i<4; i++)
1222 {
1223 int32_t tx2=((i&2)<<2)+cx;
1224 int32_t ty2=((i&1)<<3)+cy;
1225 for (int32_t m = 0; m <= 1; m++)
1226 {
1227 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1228 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1229 {
1230 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1231 {
1232 bridgedetected |= (1<<i);
1233 }
1234 }
1235 else
1236 {
1237 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1238 {
1239 bridgedetected |= (1<<i);
1240 }
1241 }
1242 }
1243 }
1244
1245 // Draw damage combos
1246 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1247 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1248 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1249 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1250 || combo_class_buf[c1.type].modify_hp_amount
1251 || combo_class_buf[c2.type].modify_hp_amount;
1252
1253 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1254
1255 if(dmg)
1256 {
1257 if (bridgedetected <= 0)
1258 {
1259 for(int32_t k=0; k<16; k+=2)
1260 for(int32_t j=0; j<16; j+=2)
1261 if(((k+j)/2)%2)
1262 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1263 }
1264 else
1265 {
1266 for(int32_t i=0; i<4; i++)
1267 {
1268 if (!(bridgedetected & (1<<i)))
1269 {
1270 int32_t tx=((i&2)<<2)+x;
1271 int32_t ty=((i&1)<<3)+y;
1272 for(int32_t k=0; k<8; k+=2)
1273 for(int32_t j=0; j<8; j+=2)
1274 if(((k+j)/2)%2)
1275 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1276 }
1277 }
1278 }
1279 }
1280
1281 if(c.type == cSLOPE)
1282 {
1283 slope_info s(c, x, y);
1284 s.draw(dest, 0, 0, COLOR_SLOPE);
1285 }
1286 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1287 auto fl1 = MAPFLAG3(map,screen,0,pos);
1288 auto fl2 = MAPFLAG3(map,screen,1,pos);
1289 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1290 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1291 {
1292 bool top = false;
1293 if(cy)
1294 {
1295 top = true;
1296 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1301 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1302 {
1303 top = false;
1304 }
1305 }
1306 draw_ladder(dest,x,y,COLOR_LADDER,top);
1307 }
1308 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1309 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1310 {
1311 draw_platform(dest,x,y,COLOR_LADDER);
1312 }
1313 }
1314
1315 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1316 {
1317 const newcombo& c = combobuf[cmbdat];
1318
1319 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1320
1321 for(int32_t i=0; i<4; i++)
1322 {
1323 int32_t tx=((i&2)<<2)+x;
1324 int32_t ty=((i&1)<<3)+y;
1325
1326 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1327 {
1328 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1329 {
1330 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1331 }
1332 else
1333 {
1334 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1335 }
1336 }
1337
1338
1339 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1340 {
1341 for(int32_t k=0; k<8; k+=2)
1342 for(int32_t j=0; j<8; j+=2)
1343 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1344 }
1345 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1346 {
1347 if(c.type==cLADDERHOOKSHOT)
1348 {
1349 for(int32_t k=0; k<8; k+=2)
1350 for(int32_t j=0; j<8; j+=2)
1351 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1352 }
1353 else
1354 {
1355 int32_t color = COLOR_SOLID;
1356
1357 if(c.type==cLADDERONLY)
1358 color=vc(6);
1359 else if(c.type==cHOOKSHOTONLY)
1360 color=vc(7);
1361
1362 rectfill(dest,tx,ty,tx+7,ty+7,color);
1363 }
1364 }
1365
1366 // Draw damage combos
1367 if(combo_class_buf[c.type].modify_hp_amount != 0)
1368 {
1369 for(int32_t k=0; k<8; k+=2)
1370 for(int32_t j=0; j<8; j+=2)
1371 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1372 }
1373 }
1374
1375 if(c.type == cSLOPE)
1376 {
1377 slope_info s(c, 0, 0);
1378 zfix const& slope = s.slope();
1379
1380 BITMAP* sub = create_bitmap_ex(8,16,16);
1381 clear_bitmap(sub);
1382 s.draw(sub, 0, 0, COLOR_SLOPE);
1383 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1384 destroy_bitmap(sub);
1385 }
1386 if(c.flag == mfSIDEVIEWLADDER)
1387 {
1388 draw_ladder(dest,x,y,COLOR_LADDER);
1389 }
1390 else if(c.flag == mfSIDEVIEWPLATFORM)
1391 {
1392 draw_platform(dest,x,y,COLOR_LADDER);
1393 }
1394 }
1395
1396 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1397 {
1398 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1399 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1400 }
1401 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1402 {
1403
1404 newcombo const& c = combobuf[cmbdat];
1405
1406 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1407 {
1408 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1409 // text_mode(-1);
1410 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1411 if(sflag)
1412 {
1413 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1414 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1415 }
1416
1417 if(c.flag)
1418 {
1419 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1420 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1421 }
1422 }
1423
1424 if(flags&cCSET)
1425 {
1426 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1427 // text_mode(inv?vc(15):vc(0));
1428 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1429 }
1430 else if(flags&cCTYPE)
1431 {
1432 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1433 // text_mode(inv?vc(15):vc(0));
1434 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1435 }
1436 }
1437
1438 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1439 {
1440 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1441
1442 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1443 if(repos)
1444 {
1445 combotile_override_x = x+(8*(scale-1));
1446 combotile_override_y = y+(8*(scale-1));
1447 }
1448 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1449 if(repos) combotile_override_x = combotile_override_y = -1;
1450 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1451 destroy_bitmap(b);
1452 }
1453 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1454 {
1455 static newcombo nilcombo;
1456 nilcombo.tile = 0;
1457
1458 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1459
1460 if(c.tile==0)
1461 {
1462 rectfill(dest,x,y,x+15,y+15,vc(0));
1463 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1464 return;
1465 }
1466
1467 putcombo(dest,x,y,cmbdat,cset);
1468
1469 /* moved to put_walkflags
1470 for(int32_t i=0; i<4; i++) {
1471
1472 int32_t tx=((i&2)<<2)+x;
1473 int32_t ty=((i&1)<<3)+y;
1474 if((flags&cWALK) && (c.walk&(1<<i)))
1475 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1476 }
1477 */
1478
1479 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1480 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1481 {
1482 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1483 // text_mode(-1);
1484 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1485 if(sflag)
1486 {
1487 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1488 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1489 }
1490
1491 if(combobuf[cmbdat].flag)
1492 {
1493 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1494 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1495 }
1496 }
1497
1498 if(flags&cWALK)
1499 {
1500 put_walkflags(dest,x,y,cmbdat,0);
1501 }
1502
1503 if(flags&cCSET)
1504 {
1505 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1506 // text_mode(inv?vc(15):vc(0));
1507 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1508 }
1509 else if(flags&cCTYPE)
1510 {
1511 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1512 // text_mode(inv?vc(15):vc(0));
1513 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1514 }
1515 }
1516 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1517 {
1518 auto blitx = 1 + (slot % 16) * 17;
1519 auto blity = 1 + (slot / 16) * 17;
1520 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1521 }
1522
1523
1524 void copy_mapscr(mapscr *dest, const mapscr *src)
1525 {
1526 if(!dest || !src) return;
1527 *dest = *src;
1528 }
1529
1530 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1531 {
1532 int32_t x=0,y=0;
1533 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1534
1535 switch(side)
1536 {
1537 case up:
1538 case down:
1539 x=((pos&15)<<4)+xofs;
1540 y=(ignorepos?0:(pos&0xF0))+yofs;
1541 break;
1542
1543 case left:
1544 case right:
1545 x=(ignorepos?0:((pos&15)<<4))+xofs;
1546 y=(pos&0xF0)+yofs;
1547 break;
1548 }
1549
1550 switch(type)
1551 {
1552 case dt_lock:
1553 case dt_shut:
1554 case dt_boss:
1555 case dt_bomb:
1556 switch(side)
1557 {
1558 case up:
1559 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1560 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1561 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1562 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1563 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1564 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1565 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1566 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1567 break;
1568
1569 case down:
1570 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1571 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1572 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1573 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1574 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1575 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1576 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1577 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1578 break;
1579
1580 case left:
1581 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1582 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1583 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1584 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1585 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1586 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1587
1588 if(x+16 >= dest->w)
1589 break;
1590
1591 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1592 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1593 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1594 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1595 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1596 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1597 break;
1598
1599 case right:
1600
1601 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1602 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1603 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1604 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1605 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1606 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1607
1608 if(x+16 <= 0)
1609 break;
1610
1611 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1612 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1613 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1614 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1615 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1616 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1617 break;
1618 }
1619
1620 break;
1621
1622 case dt_pass:
1623 case dt_wall:
1624 case dt_walk:
1625 default:
1626 break;
1627 }
1628 }
1629
1630 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1631 {
1632 int32_t x=((pos&15)<<4)+xofs;
1633 int32_t y=(pos&0xF0)+yofs;
1634 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1635
1636
1637 switch(side)
1638 {
1639 case up:
1640 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1641 {
1642 overcombo(dest,x,y,
1643 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1644 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1645 }
1646
1647 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1648 {
1649 overcombo(dest,x+16,y,
1650 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1651
1652 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1653 }
1654
1655 break;
1656
1657 case down:
1658 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1659 {
1660 overcombo(dest,x,y,
1661 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1662 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1663 }
1664
1665 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1666 {
1667 overcombo(dest,x+16,y,
1668 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1669 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1670 }
1671
1672 break;
1673
1674 case left:
1675 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1676 {
1677 overcombo(dest,x,y,
1678 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1679 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1680 }
1681
1682 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1683 {
1684 overcombo(dest,x,y+16,
1685 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1686 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1687 }
1688
1689 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1690 {
1691 overcombo(dest,x,y+32,
1692 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1693 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1694 }
1695
1696 break;
1697
1698 case right:
1699 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1700 {
1701 overcombo(dest,x,y,
1702 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1703 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1704 }
1705
1706 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1707 {
1708 overcombo(dest,x,y+16,
1709
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1712 }
1713
1714 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1715 {
1716 overcombo(dest,x,y+32,
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1719 }
1720
1721 break;
1722 }
1723 }
1724
1725 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1726 {
1727 word cmbcheck1, cmbcheck2;
1728 newcombo combocheck1, combocheck2;
1729 combocheck1 = combobuf[0];
1730 combocheck2 = combobuf[0];
1731 combocheck1.walk = 0;
1732 combocheck2.walk = 0;
1733
1734 int32_t layermap, layerscreen;
1735
1736 switch(dir)
1737 {
1738 case up:
1739 {
1740 if(i>15) //not top row of combos
1741 {
1742 return false;
1743 }
1744
1745 if(scr<16) //top row of screens
1746 {
1747 return false;
1748
1749 }
1750
1751 //check main screen
1752 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1753 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1754 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1755 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1756
1757 //check layer 1
1758 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1759
1760 if(layermap>-1 && layermap<map_count)
1761 {
1762 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1763 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1764 if (combobuf[cmbcheck1].type == cBRIDGE)
1765 {
1766 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1767 {
1768 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1769 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1770 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1771 }
1772 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1773 }
1774 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1775 }
1776
1777 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1778
1779 if(layermap>-1 && layermap<map_count)
1780 {
1781 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1782 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1783 if (combobuf[cmbcheck2].type == cBRIDGE)
1784 {
1785 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1786 {
1787 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1788 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1789 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1790 }
1791 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1792 }
1793 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1794 }
1795
1796 //check layer 2
1797 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1798
1799 if(layermap>-1 && layermap<map_count)
1800 {
1801 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1802
1803 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1804 if (combobuf[cmbcheck2].type == cBRIDGE)
1805 {
1806 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1807 {
1808 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1809 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1810 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1811 }
1812 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1813 }
1814 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1815 }
1816
1817 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1818
1819 if(layermap>-1 && layermap<map_count)
1820 {
1821 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1822 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1823 if (combobuf[cmbcheck2].type == cBRIDGE)
1824 {
1825 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1826 {
1827 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1828 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1829 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1830 }
1831 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1832 }
1833 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1834 }
1835
1836 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1837 {
1838 return true;
1839 }
1840
1841 break;
1842 }
1843 case down:
1844 {
1845 if(i<160) //not bottom row of combos
1846 {
1847 return false;
1848 }
1849
1850 if(scr>111) //bottom row of screens
1851 {
1852 return false;
1853 }
1854
1855 //check main screen
1856 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1857 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1858 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1859 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1860
1861
1862 //check layer 1
1863 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1864
1865 if(layermap>-1 && layermap<map_count)
1866 {
1867 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1868 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1869 if (combobuf[cmbcheck1].type == cBRIDGE)
1870 {
1871 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1872 {
1873 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1874 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1875 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1876 }
1877 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1878 }
1879 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1880 }
1881
1882 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1883
1884 if(layermap>-1 && layermap<map_count)
1885 {
1886 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1887 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1888 if (combobuf[cmbcheck2].type == cBRIDGE)
1889 {
1890 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1891 {
1892 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1893 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1894 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1895 }
1896 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1897 }
1898 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1899 }
1900
1901 //check layer 2
1902 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1903
1904 if(layermap>-1 && layermap<map_count)
1905 {
1906 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1907 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1908 if (combobuf[cmbcheck1].type == cBRIDGE)
1909 {
1910 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1911 {
1912 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1913 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1914 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1915 }
1916 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1917 }
1918 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1919 }
1920
1921 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1922
1923 if(layermap>-1 && layermap<map_count)
1924 {
1925 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1926 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1927 if (combobuf[cmbcheck2].type == cBRIDGE)
1928 {
1929 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1930 {
1931 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1932 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1933 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1934 }
1935 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1936 }
1937 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1938 }
1939
1940 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1941 {
1942 return true;
1943 }
1944
1945 break;
1946 }
1947 case left:
1948 {
1949 if((i&0xF)!=0) //not left column of combos
1950 {
1951 return false;
1952 }
1953
1954 if((scr&0xF)==0) //left column of screens
1955 {
1956 return false;
1957 }
1958
1959 //check main screen
1960 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1961 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1962 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1963 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1964
1965 //check layer 1
1966 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1967
1968 if(layermap>-1 && layermap<map_count)
1969 {
1970 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1971 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1972 if (combobuf[cmbcheck1].type == cBRIDGE)
1973 {
1974 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1975 {
1976 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1977 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1978 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1979 }
1980 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1981 }
1982 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1983 }
1984
1985 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1986
1987 if(layermap>-1 && layermap<map_count)
1988 {
1989 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1990 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1991 if (combobuf[cmbcheck2].type == cBRIDGE)
1992 {
1993 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1994 {
1995 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1996 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1997 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1998 }
1999 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2000 }
2001 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2002 }
2003
2004 //check layer 2
2005 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2006
2007 if(layermap>-1 && layermap<map_count)
2008 {
2009 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2010 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2011 if (combobuf[cmbcheck1].type == cBRIDGE)
2012 {
2013 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2014 {
2015 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2016 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2017 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2018 }
2019 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2020 }
2021 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2022 }
2023
2024 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2025
2026 if(layermap>-1 && layermap<map_count)
2027 {
2028 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2029 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2030 if (combobuf[cmbcheck2].type == cBRIDGE)
2031 {
2032 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2033 {
2034 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2035 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2036 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2037 }
2038 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2039 }
2040 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2041 }
2042
2043 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2044 {
2045 return true;
2046 }
2047
2048 break;
2049 }
2050 case right:
2051 {
2052 if((i&0xF)!=15) //not right column of combos
2053 {
2054 return false;
2055 }
2056
2057 if((scr&0xF)==15) //right column of screens
2058 {
2059 return false;
2060 }
2061
2062 //check main screen
2063 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2064 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2065 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2066 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2067
2068 //check layer 1
2069 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2070
2071 if(layermap>-1 && layermap<map_count)
2072 {
2073 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2074 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2075 if (combobuf[cmbcheck1].type == cBRIDGE)
2076 {
2077 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2078 {
2079 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2080 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2081 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2082 }
2083 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2084 }
2085 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2086 }
2087
2088 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2089
2090 if(layermap>-1 && layermap<map_count)
2091 {
2092 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2093 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2094 if (combobuf[cmbcheck2].type == cBRIDGE)
2095 {
2096 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2097 {
2098 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2099 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2100 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2101 }
2102 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2103 }
2104 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2105 }
2106
2107 //check layer 2
2108 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2109
2110 if(layermap>-1 && layermap<map_count)
2111 {
2112 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2113 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2114 if (combobuf[cmbcheck1].type == cBRIDGE)
2115 {
2116 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2117 {
2118 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2119 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2120 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2121 }
2122 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2123 }
2124 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2125 }
2126
2127 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2128
2129 if(layermap>-1 && layermap<map_count)
2130 {
2131 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2132
2133 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2134 if (combobuf[cmbcheck2].type == cBRIDGE)
2135 {
2136 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2137 {
2138 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2139 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2140 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2141 }
2142 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2143 }
2144 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2145 }
2146
2147 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2148 {
2149 return true;
2150 }
2151
2152 break;
2153 }
2154 }
2155
2156 return false;
2157 }
2158
2159 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2160 {
2161 int32_t checkcombo;
2162
2163 if(alignment_arrow_timer>31)
2164 {
2165 if(scr<0)
2166 {
2167 scr=currscr;
2168 }
2169
2170 if((scr<128)) //do the misalignment arrows
2171 {
2172 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2173 {
2174 if(misaligned(currmap, scr, checkcombo, up))
2175 {
2176 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2177 }
2178 }
2179
2180 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2181 {
2182 if(misaligned(currmap, scr, checkcombo, down))
2183 {
2184 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2185 }
2186 }
2187
2188 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2189 {
2190 if(misaligned(currmap, scr, checkcombo, left))
2191 {
2192 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2193 }
2194 }
2195
2196 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2197 {
2198 if(misaligned(currmap, scr, checkcombo, right))
2199 {
2200 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2201 }
2202 }
2203
2204 int32_t tempalign;
2205
2206 //check top left corner
2207 checkcombo=0;
2208 tempalign=0;
2209 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2210 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2211
2212 switch(tempalign)
2213 {
2214 case 0:
2215 break;
2216
2217 case 1: //up
2218 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2219 break;
2220
2221 case 2: //left
2222 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2223 break;
2224
2225 case 3: //up-left
2226 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2227 break;
2228 }
2229
2230 //check top right corner
2231 checkcombo=15;
2232 tempalign=0;
2233 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2234 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2235
2236 switch(tempalign)
2237 {
2238 case 0:
2239 break;
2240
2241 case 1: //up
2242 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2243 break;
2244
2245 case 2: //right
2246 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2247 break;
2248
2249 case 3: //up-right
2250 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2251 break;
2252 }
2253
2254 //check bottom left corner
2255 checkcombo=160;
2256 tempalign=0;
2257 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2258 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2259
2260 switch(tempalign)
2261 {
2262 case 0:
2263 break;
2264
2265 case 1: //down
2266 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2267 break;
2268
2269 case 2: //left
2270 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2271 break;
2272
2273 case 3: //down-left
2274 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2275 break;
2276 }
2277
2278 //check bottom right corner
2279
2280 checkcombo=175;
2281 tempalign=0;
2282 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2283 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2284
2285 switch(tempalign)
2286 {
2287 case 0:
2288 break;
2289
2290 case 1: //down
2291 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2292 break;
2293
2294 case 2: //right
2295 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2296 break;
2297
2298 case 3: //down-right
2299 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2300 break;
2301 }
2302 }
2303 }
2304 }
2305
2306 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2307 {
2308 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2309 }
2310
2311 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2312 {
2313 if (map < 0 || screen < 0) return 0;
2314
2315 if(pos>175 || pos < 0)
2316 return 0;
2317
2318 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2319
2320 if(m->valid==0) return 0;
2321
2322 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2323
2324 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2325
2326 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2327
2328 if(scr->valid==0) return 0;
2329
2330 return scr->data[pos]; // entire combo code
2331 }
2332
2333 // Takes array index layer num., not actual layer num.
2334 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2335 {
2336 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2337
2338 if(map<0)
2339 map=currmap;
2340
2341 if(scr<0)
2342 scr=currscr;
2343
2344 mapscr *screen1;
2345
2346 if(prv_mode)
2347 {
2348 screen1=get_prvscr();
2349 }
2350 else
2351 {
2352 screen1=AbsoluteScr(currmap,currscr);
2353 }
2354
2355 int32_t layermap;
2356 layermap=screen1->layermap[lyr]-1;
2357
2358 if(layermap<0 || layermap >= map_count) return 0;
2359
2360 mapscr *layer;
2361
2362 if(prv_mode)
2363 layer = &prvlayers[lyr];
2364 else
2365 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2366
2367 int32_t combo = COMBOPOS(x,y);
2368
2369 if(combo>175 || combo < 0)
2370 return 0;
2371
2372 return layer->data[combo];
2373 }
2374
2375 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2376 {
2377 if(map<0)
2378 map=currmap;
2379
2380 if(scr<0)
2381 scr=currscr;
2382
2383 mapscr *screen1;
2384
2385 if(prv_mode)
2386 {
2387 screen1=get_prvscr();
2388 }
2389 else
2390 {
2391 screen1=AbsoluteScr(currmap,currscr);
2392 }
2393
2394 x = vbound(x, 0, 16*16);
2395 y = vbound(y, 0, 11*16);
2396 int32_t combo = COMBOPOS(x,y);
2397
2398 if(combo>175 || combo < 0)
2399 return 0;
2400
2401 return screen1->data[combo];
2402 }
2403
2404 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2405 {
2406 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2407 }
2408
2409 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2410 {
2411 if (map < 0 || screen < 0) return 0;
2412
2413 if(pos>175 || pos < 0)
2414 return 0;
2415
2416 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2417
2418 if(m->valid==0) return 0;
2419
2420 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2421
2422 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2423
2424 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2425
2426 if(scr->valid==0) return 0;
2427
2428 return scr->sflag[pos]; // entire combo code
2429 }
2430
2431 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2432 {
2433 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2434
2435 if(map<0)
2436 map=currmap;
2437
2438 if(scr<0)
2439 scr=currscr;
2440
2441 mapscr *screen1;
2442
2443 if(prv_mode)
2444 {
2445 screen1=get_prvscr();
2446 }
2447 else
2448 {
2449 screen1=AbsoluteScr(currmap,currscr);
2450 }
2451
2452 int32_t layermap;
2453 layermap=screen1->layermap[lyr]-1;
2454
2455 if(layermap<0 || layermap >= map_count) return 0;
2456
2457 mapscr *layer;
2458
2459 if(prv_mode)
2460 layer = &prvlayers[lyr];
2461 else
2462 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2463
2464 int32_t combo = COMBOPOS(x,y);
2465
2466 if(combo>175 || combo < 0)
2467 return 0;
2468
2469 return layer->sflag[combo];
2470 }
2471
2472 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2473 {
2474 if(map<0)
2475 map=currmap;
2476
2477 if(scr<0)
2478 scr=currscr;
2479
2480 mapscr *screen1;
2481
2482 if(prv_mode)
2483 {
2484 screen1=get_prvscr();
2485 }
2486 else
2487 {
2488 screen1=AbsoluteScr(currmap,currscr);
2489 }
2490
2491 x = vbound(x, 0, 16*16);
2492 y = vbound(y, 0, 11*16);
2493 int32_t combo = COMBOPOS(x,y);
2494
2495 if(combo>175 || combo < 0)
2496 return 0;
2497
2498 return screen1->sflag[combo];
2499 }
2500
2501 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2502 {
2503 mapscr *layers[7];
2504 mapscr *basescr;
2505 if(prv_mode)
2506 {
2507 layers[0] = &prvscr;
2508 basescr = layers[0];
2509 for(auto q = 1; q < 7; ++q)
2510 {
2511 if(prvlayers[q-1].valid)
2512 layers[q] = &(prvlayers[q-1]);
2513 else layers[q] = NULL;
2514 }
2515 }
2516 else
2517 {
2518 layers[0] = AbsoluteScr(currmap, currscr);
2519 basescr = layers[0];
2520 for(auto q = 1; q < 7; ++q)
2521 {
2522 int32_t lmap = basescr->layermap[q-1]-1;
2523 int32_t lscr = basescr->layerscreen[q-1];
2524 if(lmap < 0)
2525 layers[q] = NULL;
2526 else layers[q] = AbsoluteScr(lmap, lscr);
2527 }
2528 }
2529 for(auto q = 0; q < 7; ++q)
2530 {
2531 if(!layers[q]) continue;
2532 for(auto pos = 0; pos < 176; ++pos)
2533 {
2534 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2535 if(cmb.type == cTORCH)
2536 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2537 }
2538 }
2539 word maxffc = basescr->numFFC();
2540 for(auto q = 0; q < maxffc; ++q)
2541 {
2542 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2543 if(cmb.type == cTORCH)
2544 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2545 }
2546 }
2547
2548 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2549 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2550 {
2551 newcombo const& cmb = combobuf[cid];
2552 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2553 if(dither)
2554 {
2555 if (LayerDitherSz == 0)
2556 return;
2557 BITMAP* buf = create_bitmap_ex(8,16,16);
2558 clear_bitmap(buf);
2559 overcombo(buf,0,0,cid,cset);
2560 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2561 if(over)
2562 {
2563 if(transp)
2564 {
2565 color_map = &trans_table2;
2566 draw_trans_sprite(dest, buf, x, y);
2567 color_map = &trans_table;
2568 }
2569 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2570 }
2571 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2572 destroy_bitmap(buf);
2573 }
2574 else if(over)
2575 {
2576 if(transp)
2577 overcombotranslucent(dest,x,y,cid,cset,0);
2578 else overcombo(dest,x,y,cid,cset);
2579 }
2580 else put_combo(dest,x,y,cid,cset,flags,sflag);
2581 }
2582 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2583 {
2584 if(!md) return;
2585 for (int32_t i = 0; i < 176; i++)
2586 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2587 }
2588 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2589 {
2590 if(!md) return;
2591 for (int32_t i = 0; i < 176; i++)
2592 {
2593 int data = md->data[i];
2594 if(combo_class_buf[combobuf[data].type].overhead)
2595 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2596 }
2597 }
2598 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2599 {
2600 if(!LayerMaskInt[lyr])
2601 return nullptr;
2602 if(lyr == 0)
2603 return basescr;
2604 int layermap = basescr->layermap[lyr-1]-1;
2605
2606 if(layermap>-1 && layermap<map_count)
2607 {
2608 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2609 return &TheMaps[layerscreen];
2610 }
2611 return nullptr;
2612 }
2613 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2614 {
2615 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2616 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2617
2618 if(map<0)
2619 map=currmap;
2620
2621 if(scr<0)
2622 scr=currscr;
2623
2624 mapscr *basescr;
2625 mapscr* layers[7] = {nullptr};
2626
2627 if(prv_mode)
2628 {
2629 hl_layer = -1;
2630 basescr=get_prvscr();
2631 }
2632 else
2633 {
2634 basescr=AbsoluteScr(map,scr);
2635 }
2636 layers[0] = _zmap_get_lyr_checked(0,basescr);
2637 for(int lyr = 1; lyr < 7; ++lyr)
2638 {
2639 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2640 : _zmap_get_lyr_checked(lyr,basescr);
2641 }
2642
2643 int32_t layermap, layerscreen;
2644 if(CurrentLayer < 1)
2645 layermap = -1;
2646 else
2647 {
2648 layermap=basescr->layermap[CurrentLayer-1]-1;
2649
2650 if(layermap<0)
2651 CurrentLayer=0;
2652 }
2653
2654 if(!(basescr->valid&mVALID))
2655 {
2656 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2657 rectfill(dest,x,y,x+255,y+175,vc(1));
2658
2659 if(ShowMisalignments)
2660 {
2661 check_alignments(dest,x,y,scr);
2662 }
2663
2664 return;
2665 }
2666
2667 if(LayerMaskInt[0]==0)
2668 {
2669 byte bgfill = 0;
2670 if (LayerDitherBG > -1)
2671 bgfill = vc(LayerDitherBG);
2672 rectfill(dest,x,y,x+255,y+175,bgfill);
2673 }
2674
2675 resize_mouse_pos=true;
2676 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2677 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2678
2679 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2680 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2681
2682 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2683
2684 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2685
2686 for(int32_t i=MAXFFCS-1; i>=0; i--)
2687 {
2688 if(basescr->ffcs[i].data)
2689 {
2690 if(!(basescr->ffcs[i].flags&ffc_changer))
2691 {
2692 if(!(basescr->ffcs[i].flags&ffc_overlay))
2693 {
2694 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2695 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2696
2697 if(basescr->ffcs[i].flags&ffc_trans)
2698 {
2699 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2700 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2701 }
2702 else
2703 {
2704 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2705 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2706 }
2707 }
2708 }
2709 }
2710 }
2711
2712 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2713 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2714
2715 int32_t doortype[4];
2716
2717 for(int32_t i=0; i<4; i++)
2718 {
2719 switch(basescr->door[i])
2720 {
2721 case dOPEN:
2722 doortype[i]=dt_pass;
2723 break;
2724
2725 case dLOCKED:
2726 doortype[i]=dt_lock;
2727 break;
2728
2729 case d1WAYSHUTTER:
2730 case dSHUTTER:
2731 doortype[i]=dt_shut;
2732 break;
2733
2734 case dBOSS:
2735 doortype[i]=dt_boss;
2736 break;
2737
2738 case dBOMB:
2739 doortype[i]=dt_bomb;
2740 break;
2741 }
2742 }
2743
2744 switch(basescr->door[up])
2745 {
2746 case dBOMB:
2747 over_door(dest,39,up,x,y,false, scr);
2748 [[fallthrough]];
2749 case dOPEN:
2750 case dLOCKED:
2751 case d1WAYSHUTTER:
2752 case dSHUTTER:
2753 case dBOSS:
2754 put_door(dest,7,up,doortype[up],x,y,false,scr);
2755 break;
2756
2757 case dWALK:
2758 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2759 {
2760 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2761 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2762 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2763 }
2764 else
2765
2766 {
2767 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2768 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2769 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2770 }
2771
2772 break;
2773 }
2774
2775 switch(basescr->door[down])
2776 {
2777 case dBOMB:
2778 over_door(dest,135,down,x,y,false,scr);
2779 [[fallthrough]];
2780 case dOPEN:
2781 case dLOCKED:
2782 case d1WAYSHUTTER:
2783 case dSHUTTER:
2784 case dBOSS:
2785 put_door(dest,151,down,doortype[down],x,y,false,scr);
2786 break;
2787
2788 case dWALK:
2789 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2790 {
2791 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2792 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2793 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2794 }
2795 else
2796 {
2797 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2798 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2799 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2800 }
2801
2802 break;
2803 }
2804
2805 switch(basescr->door[left])
2806 {
2807 case dBOMB:
2808 over_door(dest,66,left,x,y,false,scr);
2809 [[fallthrough]];
2810 case dOPEN:
2811 case dLOCKED:
2812 case d1WAYSHUTTER:
2813 case dSHUTTER:
2814 case dBOSS:
2815 put_door(dest,64,left,doortype[left],x,y,false,scr);
2816 break;
2817
2818 case dWALK:
2819 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2820 {
2821 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2822 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2823 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2824 }
2825 else
2826 {
2827 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2828 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2829 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2830 }
2831
2832 break;
2833 }
2834
2835 switch(basescr->door[right])
2836 {
2837
2838 case dBOMB:
2839 over_door(dest,77,right,x,y,false,scr);
2840 [[fallthrough]];
2841 case dOPEN:
2842 case dLOCKED:
2843 case d1WAYSHUTTER:
2844 case dSHUTTER:
2845 case dBOSS:
2846 put_door(dest,78,right,doortype[right],x,y,false,scr);
2847 break;
2848
2849 case dWALK:
2850 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2851 {
2852 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2853 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2854 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2855 }
2856 else
2857 {
2858 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2859 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2860 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2861 }
2862
2863 break;
2864 }
2865
2866 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2867 {
2868 frame=0;
2869 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2870 }
2871
2872 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2873 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2874 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2875
2876 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2877
2878 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2879 {
2880 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2881 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2882 }
2883 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2884
2885 for(int32_t i=MAXFFCS-1; i>=0; i--)
2886 {
2887 if(basescr->ffcs[i].data)
2888 {
2889 if(!(basescr->ffcs[i].flags&ffc_changer))
2890 {
2891 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2892 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2893
2894 if(basescr->ffcs[i].flags&ffc_overlay)
2895 {
2896 if(basescr->ffcs[i].flags&ffc_trans)
2897 {
2898 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2899 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2900 }
2901 else
2902 {
2903 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2904 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2905 }
2906 }
2907 }
2908 }
2909 }
2910
2911 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2912
2913 for(int32_t i=MAXFFCS-1; i>=0; i--)
2914 if(basescr->ffcs[i].data)
2915 if(basescr->ffcs[i].flags&ffc_changer)
2916 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2917
2918 if(flags&cWALK)
2919 {
2920 if(layers[0])
2921 for(int32_t i=0; i<176; i++)
2922 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2923
2924 for(int32_t k=0; k<2; k++)
2925 {
2926 if(layers[k+1])
2927 for(int32_t i=0; i<176; i++)
2928 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2929 }
2930 for(int32_t i=MAXFFCS-1; i>=0; i--)
2931 {
2932 if(auto data = basescr->ffcs[i].data)
2933 {
2934 if(!(basescr->ffcs[i].flags&ffc_changer))
2935 {
2936 newcombo const& cmb = combobuf[data];
2937 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2938 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2939
2940 if(basescr->ffcs[i].flags&ffc_solid)
2941 {
2942 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2943 }
2944
2945 if(cmb.type == cSLOPE)
2946 {
2947 slope_info s(cmb, tx, ty);
2948 s.draw(dest, 0, 0, COLOR_SLOPE);
2949 }
2950 }
2951 }
2952 }
2953 }
2954
2955 if(flags&cFLAGS)
2956 {
2957 if(LayerMaskInt[CurrentLayer]!=0)
2958 {
2959 for(int32_t i=0; i<176; i++)
2960 {
2961 if(CurrentLayer==0)
2962 {
2963 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2964 }
2965 else
2966 {
2967 if(prv_mode)
2968 {
2969 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2970 }
2971 else
2972 {
2973 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2974
2975 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2976 {
2977 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2978 TheMaps[_lscr].data[i],
2979 TheMaps[_lscr].cset[i], flags,
2980 TheMaps[_lscr].sflag[i]);
2981 }
2982 }
2983 }
2984 }
2985 }
2986 }
2987
2988 int32_t dark = basescr->flags&cDARK;
2989
2990 if(dark && !(flags&cNODARK)
2991 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2992 {
2993 for(int32_t j=0; j<80; j++)
2994 {
2995 for(int32_t i=0; i<(80)-j; i++)
2996 {
2997 if(((i^j)&1)==0)
2998 {
2999 putpixel(dest,x+i,y+j,vc(blackout_color));
3000 }
3001 }
3002 }
3003 }
3004
3005 if(ShowMisalignments)
3006 {
3007 check_alignments(dest,x,y,scr);
3008 }
3009
3010 resize_mouse_pos=false;
3011 }
3012
3013 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3014 {
3015 if(map<0)
3016 map=currmap;
3017
3018 if(scr<0)
3019 scr=currscr;
3020
3021 mapscr* layer=AbsoluteScr(map,scr);
3022 int32_t layermap=0, layerscreen=0;
3023
3024 if(!(layer->valid&mVALID))
3025 {
3026 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3027 rectfill(dest,x,y,x+255,y+15,vc(1));
3028 return;
3029 }
3030
3031 int32_t dark = layer->flags&4;
3032
3033 resize_mouse_pos=true;
3034
3035 if(LayerMaskInt[0]==0)
3036 {
3037 rectfill(dest,x,y,x+255,y+15,0);
3038 }
3039
3040
3041 for(int32_t k=1; k<3; k++)
3042 {
3043 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3044 {
3045 layermap=layer->layermap[k]-1;
3046
3047 if(layermap>-1 && layermap<map_count)
3048 {
3049 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3050
3051 for(int32_t i=c; i<(c&0xF0)+16; i++)
3052 {
3053 auto data = TheMaps[layerscreen].data[i];
3054 auto cs = TheMaps[layerscreen].cset[i];
3055 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3056 }
3057 }
3058 }
3059 }
3060
3061 if(LayerMaskInt[0]!=0)
3062 {
3063 for(int32_t i=c; i<(c&0xF0)+16; i++)
3064 {
3065 word cmbdat = (i < 176 ? layer->data[i] : 0);
3066 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3067 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3068 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3069 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3070 }
3071 }
3072
3073 for(int32_t k=0; k<2; k++)
3074 {
3075 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3076 {
3077 layermap=layer->layermap[k]-1;
3078
3079 if(layermap>-1 && layermap<map_count)
3080 {
3081 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3082
3083 for(int32_t i=c; i<(c&0xF0)+16; i++)
3084 {
3085 auto data = TheMaps[layerscreen].data[i];
3086 auto cs = TheMaps[layerscreen].cset[i];
3087 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3088 }
3089 }
3090 }
3091 }
3092
3093 int32_t doortype[4];
3094
3095 for(int32_t i=0; i<4; i++)
3096 {
3097 switch(layer->door[i])
3098 {
3099 case dOPEN:
3100 doortype[i]=dt_pass;
3101 break;
3102
3103 case dLOCKED:
3104 doortype[i]=dt_lock;
3105 break;
3106
3107 case d1WAYSHUTTER:
3108 case dSHUTTER:
3109 doortype[i]=dt_shut;
3110 break;
3111
3112 case dBOSS:
3113 doortype[i]=dt_boss;
3114 break;
3115
3116 case dBOMB:
3117 doortype[i]=dt_bomb;
3118 break;
3119 }
3120 }
3121
3122 if(c<16)
3123 {
3124 switch(layer->door[up])
3125 {
3126 case dBOMB:
3127 case dOPEN:
3128 case dLOCKED:
3129 case d1WAYSHUTTER:
3130 case dSHUTTER:
3131 case dBOSS:
3132 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3133 break;
3134 }
3135 }
3136 else if(c>159)
3137 {
3138 switch(layer->door[down])
3139 {
3140 case dBOMB:
3141 case dOPEN:
3142 case dLOCKED:
3143 case d1WAYSHUTTER:
3144 case dSHUTTER:
3145 case dBOSS:
3146 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3147 break;
3148 }
3149 }
3150
3151 for(int32_t k=2; k<4; k++)
3152 {
3153 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3154 {
3155 layermap=layer->layermap[k]-1;
3156
3157 if(layermap>-1 && layermap<map_count)
3158 {
3159 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3160
3161 for(int32_t i=c; i<(c&0xF0)+16; i++)
3162 {
3163 if(layer->layeropacity[k]<255)
3164 {
3165 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3166 }
3167 else
3168 {
3169 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3170 }
3171 }
3172 }
3173 }
3174 }
3175
3176 //Overhead L0
3177 if(LayerMaskInt[0]!=0)
3178 {
3179 for(int32_t i=c; i<(c&0xF0)+16; i++)
3180 {
3181 int32_t ct1=layer->data[i];
3182 int32_t ct3=combobuf[ct1].type;
3183
3184 if(combo_class_buf[ct3].overhead)
3185 {
3186 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3187 }
3188 }
3189 }
3190
3191 //Overhead L1/2
3192 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3193 {
3194 for(int32_t k = 0; k < 2; ++k)
3195 {
3196 if(LayerMaskInt[k+1]!=0)
3197 {
3198 layermap=layer->layermap[k]-1;
3199
3200 if(layermap>-1 && layermap<map_count)
3201 {
3202 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3203 for(int32_t i=c; i<(c&0xF0)+16; i++)
3204 {
3205 auto data = TheMaps[layerscreen].data[i];
3206 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3207 auto cs = TheMaps[layerscreen].cset[i];
3208 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3209 }
3210 }
3211 }
3212 }
3213 }
3214
3215 for(int32_t k=4; k<6; k++)
3216 {
3217 if(LayerMaskInt[k+1]!=0)
3218 {
3219 layermap=layer->layermap[k]-1;
3220
3221 if(layermap>-1 && layermap<map_count)
3222 {
3223 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3224
3225 for(int32_t i=c; i<(c&0xF0)+16; i++)
3226 {
3227 auto data = TheMaps[layerscreen].data[i];
3228 auto cs = TheMaps[layerscreen].cset[i];
3229 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3230 }
3231 }
3232 }
3233 }
3234
3235 if(flags&cWALK)
3236 {
3237 if(LayerMaskInt[0]!=0)
3238 {
3239 for(int32_t i=c; i<(c&0xF0)+16; i++)
3240 {
3241 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3242 }
3243 }
3244
3245 for(int32_t k=0; k<2; k++)
3246 {
3247 if(LayerMaskInt[k+1]!=0)
3248 {
3249 for(int32_t i=c; i<(c&0xF0)+16; i++)
3250 {
3251 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3252 }
3253 }
3254 }
3255 }
3256
3257 if(flags&cFLAGS)
3258 {
3259 if(LayerMaskInt[CurrentLayer]!=0)
3260 {
3261 for(int32_t i=c; i<(c&0xF0)+16; i++)
3262 {
3263 if(CurrentLayer==0)
3264 {
3265 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3266 }
3267 else
3268 {
3269 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3270
3271 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3272 {
3273 if(i < 176)
3274 {
3275 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3276 TheMaps[_lscr].data[i],
3277 TheMaps[_lscr].cset[i], flags|dark,
3278 TheMaps[_lscr].sflag[i]);
3279 }
3280 else
3281 {
3282 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3283 }
3284 }
3285 }
3286 }
3287 }
3288
3289 /*
3290 if (LayerMaskInt[0]!=0) {
3291 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3292 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3293 }
3294 }
3295 */
3296 }
3297
3298 if(ShowMisalignments)
3299 {
3300 if(c<16)
3301 {
3302 check_alignments(dest,x,y,scr);
3303 }
3304 else if(c>159)
3305 {
3306 check_alignments(dest,x,y-160,scr);
3307 }
3308 }
3309
3310 resize_mouse_pos=false;
3311
3312 }
3313
3314 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3315 {
3316 if(map<0)
3317 map=currmap;
3318
3319 if(scr<0)
3320 scr=currscr;
3321
3322 mapscr* layer=AbsoluteScr(map,scr);
3323 int32_t layermap=0, layerscreen=0;
3324
3325 if(!(layer->valid&mVALID))
3326 {
3327 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3328 rectfill(dest,x,y,x+15,y+175,vc(1));
3329 return;
3330 }
3331
3332 int32_t dark = layer->flags&4;
3333
3334 resize_mouse_pos=true;
3335
3336
3337 if(LayerMaskInt[0]==0)
3338 {
3339 rectfill(dest,x,y,x+15,y+175,0);
3340 }
3341
3342
3343 for(int32_t k=1; k<3; k++)
3344 {
3345 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3346 {
3347 layermap=layer->layermap[k]-1;
3348
3349 if(layermap>-1 && layermap<map_count)
3350 {
3351 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3352
3353 for(int32_t i=c; i<176; i+=16)
3354 {
3355 auto data = TheMaps[layerscreen].data[i];
3356 auto cs = TheMaps[layerscreen].cset[i];
3357 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3358 }
3359 }
3360 }
3361 }
3362
3363 if(LayerMaskInt[0]!=0)
3364 {
3365 for(int32_t i=c; i<176; i+=16)
3366 {
3367 word cmbdat = layer->data[i];
3368 byte cmbcset = layer->cset[i];
3369 int32_t cmbflag = layer->sflag[i];
3370 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3371 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3372 }
3373 }
3374
3375 for(int32_t k=0; k<2; k++)
3376 {
3377 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3378 {
3379 layermap=layer->layermap[k]-1;
3380
3381 if(layermap>-1 && layermap<map_count)
3382 {
3383 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3384
3385 for(int32_t i=c; i<176; i+=16)
3386 {
3387 auto data = TheMaps[layerscreen].data[i];
3388 auto cs = TheMaps[layerscreen].cset[i];
3389 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3390 }
3391 }
3392 }
3393 }
3394
3395 int32_t doortype[4];
3396
3397 for(int32_t i=0; i<4; i++)
3398 {
3399 switch(layer->door[i])
3400 {
3401 case dOPEN:
3402 doortype[i]=dt_pass;
3403 break;
3404
3405 case dLOCKED:
3406 doortype[i]=dt_lock;
3407 break;
3408
3409 case d1WAYSHUTTER:
3410 case dSHUTTER:
3411 doortype[i]=dt_shut;
3412 break;
3413
3414 case dBOSS:
3415 doortype[i]=dt_boss;
3416 break;
3417
3418 case dBOMB:
3419 doortype[i]=dt_bomb;
3420 break;
3421 }
3422 }
3423
3424 if((c&0x0F)==0)
3425 {
3426 switch(layer->door[left])
3427 {
3428
3429 case dBOMB:
3430 case dOPEN:
3431 case dLOCKED:
3432 case d1WAYSHUTTER:
3433 case dSHUTTER:
3434 case dBOSS:
3435 // put_door(dest,64,left,doortype[left],x+256,y,true);
3436 put_door(dest,64,left,doortype[left],x,y,true,scr);
3437 break;
3438 }
3439 }
3440 else if((c&0x0F)==15)
3441 {
3442 switch(layer->door[right])
3443 {
3444 case dBOMB:
3445 case dOPEN:
3446 case dLOCKED:
3447 case d1WAYSHUTTER:
3448 case dSHUTTER:
3449 case dBOSS:
3450 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3451 break;
3452 }
3453 }
3454
3455 for(int32_t k=2; k<4; k++)
3456 {
3457 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3458 {
3459 layermap=layer->layermap[k]-1;
3460
3461 if(layermap>-1 && layermap<map_count)
3462 {
3463 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3464
3465 for(int32_t i=c; i<176; i+=16)
3466 {
3467 auto data = TheMaps[layerscreen].data[i];
3468 auto cs = TheMaps[layerscreen].cset[i];
3469 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3470 }
3471 }
3472 }
3473 }
3474
3475 //Overhead L0
3476 if(LayerMaskInt[0]!=0)
3477 {
3478 for(int32_t i=c; i<176; i+=16)
3479 {
3480 auto data = TheMaps[layerscreen].data[i];
3481 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3482 auto cs = TheMaps[layerscreen].cset[i];
3483 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3484 }
3485 }
3486 //Overhead L1/2
3487 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3488 {
3489 for(int32_t k = 0; k < 2; ++k)
3490 {
3491 if(LayerMaskInt[k+1]!=0)
3492 {
3493 layermap=layer->layermap[k]-1;
3494
3495 if(layermap>-1 && layermap<map_count)
3496 {
3497 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3502 auto cs = TheMaps[layerscreen].cset[i];
3503 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3504 }
3505 }
3506 }
3507 }
3508 }
3509
3510
3511 for(int32_t k=4; k<6; k++)
3512 {
3513 if(LayerMaskInt[k+1]!=0)
3514 {
3515 layermap=layer->layermap[k]-1;
3516
3517 if(layermap>-1 && layermap<map_count)
3518 {
3519 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3520
3521 for(int32_t i=c; i<176; i+=16)
3522 {
3523 auto data = TheMaps[layerscreen].data[i];
3524 auto cs = TheMaps[layerscreen].cset[i];
3525 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3526 }
3527 }
3528 }
3529 }
3530
3531 if(flags&cWALK)
3532 {
3533 if(LayerMaskInt[0]!=0)
3534 {
3535 for(int32_t i=c&0xF; i<176; i+=16)
3536 {
3537 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3538 }
3539 }
3540
3541 for(int32_t k=0; k<2; k++)
3542 {
3543 if(LayerMaskInt[k+1]!=0)
3544 {
3545 for(int32_t i=c&0xF; i<176; i+=16)
3546 {
3547 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3548 }
3549 }
3550 }
3551 }
3552
3553 if(flags&cFLAGS)
3554 {
3555 if(LayerMaskInt[CurrentLayer]!=0)
3556 {
3557 for(int32_t i=c; i<176; i+=16)
3558 {
3559 if(CurrentLayer==0)
3560 {
3561 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3562 }
3563 else
3564 {
3565 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3566
3567 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3568 {
3569 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3570 TheMaps[_lscr].data[i],
3571 TheMaps[_lscr].cset[i], flags|dark,
3572 TheMaps[_lscr].sflag[i]);
3573 }
3574 }
3575 }
3576 }
3577 }
3578
3579 if(ShowMisalignments)
3580 {
3581 if((c&0x0F)==0)
3582 {
3583 check_alignments(dest,x,y,scr);
3584 }
3585 else if((c&0x0F)==15)
3586 {
3587 check_alignments(dest,x-240,y,scr);
3588 }
3589 }
3590
3591 resize_mouse_pos=false;
3592 }
3593
3594 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3595 {
3596 if(map<0)
3597 map=currmap;
3598
3599 if(scr<0)
3600 scr=currscr;
3601
3602 mapscr* layer=AbsoluteScr(map,scr);
3603 int32_t layermap=0, layerscreen=0;
3604
3605 if(!(layer->valid&mVALID))
3606 {
3607 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3608 rectfill(dest,x,y,x+15,y+15,vc(1));
3609 return;
3610 }
3611
3612 int32_t dark = layer->flags&4;
3613
3614 resize_mouse_pos=true;
3615
3616 if(LayerMaskInt[0]!=0)
3617 {
3618 rectfill(dest,x,y,x+15,y+15,0);
3619 }
3620
3621 for(int32_t k=1; k<3; k++)
3622 {
3623 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3624 {
3625 layermap=layer->layermap[k]-1;
3626
3627 if(layermap>-1 && layermap<map_count)
3628 {
3629 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3630
3631 auto data = TheMaps[layerscreen].data[c];
3632 auto cs = TheMaps[layerscreen].cset[c];
3633 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3634 }
3635 }
3636 }
3637
3638 if(LayerMaskInt[0]!=0)
3639 {
3640 word cmbdat = layer->data[c];
3641 byte cmbcset = layer->cset[c];
3642 int32_t cmbflag = layer->sflag[c];
3643 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3644 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3645 }
3646
3647
3648 for(int32_t k=0; k<2; k++)
3649 {
3650 if(LayerMaskInt[k+1]!=0)
3651 {
3652 layermap=layer->layermap[k]-1;
3653
3654 if(layermap>-1 && layermap<map_count)
3655 {
3656 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3657
3658 auto data = TheMaps[layerscreen].data[c];
3659 auto cs = TheMaps[layerscreen].cset[c];
3660 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3661 }
3662 }
3663 }
3664
3665 for(int32_t k=2; k<4; k++)
3666 {
3667 if(LayerMaskInt[k+1]!=0)
3668 {
3669 layermap=layer->layermap[k]-1;
3670
3671 if(layermap>-1 && layermap<map_count)
3672 {
3673 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3674 auto data = TheMaps[layerscreen].data[c];
3675 auto cs = TheMaps[layerscreen].cset[c];
3676 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3677 }
3678 }
3679 }
3680
3681 //Overhead L0
3682 if(LayerMaskInt[0]!=0)
3683 {
3684 auto data = TheMaps[layerscreen].data[c];
3685 if(combo_class_buf[combobuf[data].type].overhead)
3686 {
3687 auto cs = TheMaps[layerscreen].cset[c];
3688 drawcombo(dest,x,y,data,cs,0,0);
3689 }
3690 }
3691 //Overhead L1/2
3692 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3693 {
3694 for(int32_t k = 0; k < 2; ++k)
3695 {
3696 if(LayerMaskInt[k+1]!=0)
3697 {
3698 layermap=layer->layermap[k]-1;
3699
3700 if(layermap>-1 && layermap<map_count)
3701 {
3702 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3703 auto data = TheMaps[layerscreen].data[c];
3704 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3705 auto cs = TheMaps[layerscreen].cset[c];
3706 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3707 }
3708 }
3709 }
3710 }
3711
3712
3713 for(int32_t k=4; k<6; k++)
3714 {
3715 if(LayerMaskInt[k+1]!=0)
3716 {
3717 layermap=layer->layermap[k]-1;
3718
3719 if(layermap>-1 && layermap<map_count)
3720 {
3721 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3722 auto data = TheMaps[layerscreen].data[c];
3723 auto cs = TheMaps[layerscreen].cset[c];
3724 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3725 }
3726 }
3727 }
3728
3729 if(flags&cWALK)
3730 {
3731 if(LayerMaskInt[0]!=0)
3732 {
3733 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3734 }
3735
3736 for(int32_t k=0; k<2; k++)
3737 {
3738 if(LayerMaskInt[k+1]!=0)
3739 {
3740 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3741 }
3742 }
3743 }
3744
3745 if(flags&cFLAGS)
3746 {
3747 if(LayerMaskInt[CurrentLayer]!=0)
3748 {
3749 int32_t i = c;
3750 //for(int32_t i=c; i==c; i++)
3751 {
3752 if(CurrentLayer==0)
3753 {
3754 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3755 }
3756 else
3757 {
3758 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3759
3760 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3761 {
3762 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3763 TheMaps[_lscr].data[i],
3764 TheMaps[_lscr].cset[i], flags|dark,
3765 TheMaps[_lscr].sflag[i]);
3766 }
3767 }
3768 }
3769 }
3770 }
3771
3772 if(ShowMisalignments)
3773 {
3774 switch(c)
3775 {
3776 case 0:
3777 check_alignments(dest,x,y,scr);
3778 break;
3779
3780 case 15:
3781 check_alignments(dest,x-240,y,scr);
3782 break;
3783
3784 case 160:
3785 check_alignments(dest,x,y-160,scr);
3786 break;
3787
3788 case 175:
3789 check_alignments(dest,x-240,y-160,scr);
3790 break;
3791 }
3792 }
3793
3794 resize_mouse_pos=false;
3795
3796 }
3797
3798 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3799 {
3800 if (InvalidBG == 2)
3801 {
3802 draw_checkerboard(dest, x, y, 16);
3803 }
3804 else if(InvalidBG == 1)
3805 {
3806 for(int32_t dy=0; dy<16; dy++)
3807 {
3808 for(int32_t dx=0; dx<16; dx++)
3809 {
3810 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3811 }
3812 }
3813 }
3814 else
3815 {
3816 rectfill(dest, x, y, x+15, y+15, vc(0));
3817 rect(dest, x, y, x+15, y+15, vc(15));
3818 line(dest, x, y, x+15, y+15, vc(15));
3819 line(dest, x, y+15, x+15, y, vc(15));
3820 }
3821 }
3822
3823 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3824 {
3825 if (InvalidBG == 2)
3826 {
3827 for(int32_t q = 0; q < 11; ++q)
3828 draw_checkerboard(dest, x, y + q * 16, 16);
3829 }
3830 else if(InvalidBG == 1)
3831 {
3832 for(int32_t dy=0; dy<176; dy++)
3833 {
3834 for(int32_t dx=0; dx<16; dx++)
3835 {
3836 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3837 }
3838 }
3839 }
3840 else
3841 {
3842 rectfill(dest, x, y, x+15, y+175, vc(0));
3843 rect(dest, x, y, x+15, y+175, vc(15));
3844 line(dest, x, y, x+15, y+175, vc(15));
3845 line(dest, x, y+175, x+15, y, vc(15));
3846 }
3847 }
3848
3849 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3850 {
3851 if (InvalidBG == 2)
3852 {
3853 for (int32_t q = 0; q < 16; ++q)
3854 draw_checkerboard(dest, x + q * 16, y, 16);
3855 }
3856 else if(InvalidBG == 1)
3857 {
3858 for(int32_t dy=0; dy<16; dy++)
3859 {
3860 for(int32_t dx=0; dx<256; dx++)
3861 {
3862 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3863 }
3864 }
3865 }
3866 else
3867 {
3868 rectfill(dest, x, y, x+255, y+15, vc(0));
3869 rect(dest, x, y, x+255, y+15, vc(15));
3870 line(dest, x, y, x+255, y+15, vc(15));
3871 line(dest, x, y+15, x+255, y, vc(15));
3872 }
3873 }
3874
3875 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3876 {
3877 for(int32_t i=0; i<176; i++)
3878 {
3879 word cmbdat = screens[TEMPLATE].data[i];
3880 byte cmbcset = screens[TEMPLATE].cset[i];
3881 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3882 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3883 }
3884 }
3885
3886 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3887 {
3888 for(int32_t i=0; i<176; i++)
3889 {
3890 word cmbdat = screens[TEMPLATE2].data[i];
3891 byte cmbcset = screens[TEMPLATE2].cset[i];
3892 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3893 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3894 }
3895 }
3896
3897 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3898 {
3899 word cmbdat = screens[TEMPLATE].data[pos];
3900 byte cmbcset = screens[TEMPLATE].cset[pos];
3901 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3902 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3903 }
3904
3905 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3906 {
3907 word cmbdat = screens[currscr].secretcombo[scombo];
3908 byte cmbcset = screens[currscr].secretcset[scombo];
3909 byte cmbflag = screens[currscr].secretflag[scombo];
3910 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3911 }
3912
3913 void zmap::scroll(int32_t dir, bool warp)
3914 {
3915 if(currmap<map_count)
3916 {
3917 switch(dir)
3918 {
3919 case up:
3920 if(warp && Map.CurrScr()->flags2&wfUP)
3921 {
3922 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3923 }
3924 else if(currscr>15)
3925 {
3926 setCurrScr(currscr-16);
3927 }
3928
3929 break;
3930
3931 case down:
3932 if(warp && Map.CurrScr()->flags2&wfDOWN)
3933 {
3934 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3935 }
3936 else if(currscr<MAPSCRS-16)
3937 {
3938 setCurrScr(currscr+16);
3939 }
3940
3941 break;
3942
3943 case left:
3944 if(warp && Map.CurrScr()->flags2&wfLEFT)
3945 {
3946 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3947 }
3948 else if(currscr&15)
3949 {
3950 setCurrScr(currscr-1);
3951 }
3952
3953 break;
3954
3955 case right:
3956 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3957 {
3958 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3959 }
3960 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3961 {
3962 setCurrScr(currscr+1);
3963 }
3964
3965 break;
3966 }
3967 }
3968 }
3969
3970 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3971 {
3972 switch(side)
3973 {
3974 case up:
3975 switch(door)
3976 {
3977 case dWALL:
3978 case dBOMB:
3979 case dWALK:
3980 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3981 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3982 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3983 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3984 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3985 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3986 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3987 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3988 break;
3989
3990 default:
3991 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3992 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3993 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3994 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3995 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3996 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3997 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3998 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3999 break;
4000 }
4001
4002 break;
4003
4004 case down:
4005 switch(door)
4006 {
4007 case dWALL:
4008 case dBOMB:
4009 case dWALK:
4010 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4011 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4012 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4013 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4014 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4015 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4016 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4017 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4018 break;
4019
4020 default:
4021 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4022 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4023 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4024 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4025 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4026 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4027 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4028 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4029 break;
4030 }
4031
4032 break;
4033
4034 case left:
4035 switch(door)
4036 {
4037 case dWALL:
4038 case dBOMB:
4039 case dWALK:
4040 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4041 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4042 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4043 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4044 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4045 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4046 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4047 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4048 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4049 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4050 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4051 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4052 break;
4053
4054 default:
4055 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4056 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4057 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4058 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4059 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4060 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4061 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4062 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4063 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4064 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4065 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4066 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4067 break;
4068 }
4069
4070 break;
4071
4072 case right:
4073 switch(door)
4074 {
4075 case dWALL:
4076 case dBOMB:
4077 case dWALK:
4078 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4079 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4080 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4081 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4082 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4083 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4084 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4085 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4086 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4087 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4088 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4089 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4090 break;
4091
4092 default:
4093 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4094 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4095 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4096 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4097 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4098 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4099 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4100 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4101 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4102 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4103 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4104 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4105 break;
4106 }
4107
4108 break;
4109 }
4110 }
4111 void zmap::DoPutDoorCommand(int side, int door, bool force)
4112 {
4113 if(!force && screens[currscr].door[side] == door)
4114 return;
4115 bool already_list = InListCommand();
4116 if(!already_list)
4117 StartListCommand();
4118 DoSetDoorCommand(currscr,side,door);
4119 if(door != dNONE)
4120 {
4121 word data[176] = {0};
4122 byte cset[176] = {0};
4123 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4124 for(int q = 0; q < 176; ++q)
4125 if(data[q])
4126 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4127 }
4128 if(!already_list)
4129 FinishListCommand();
4130 }
4131 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4132 {
4133 if(screens[scr].door[side] == door)
4134 return;
4135 screens[scr].door[side] = door;
4136 if(door != dNONE)
4137 {
4138 word data[176] = {0};
4139 byte cset[176] = {0};
4140 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4141 for(int q = 0; q < 176; ++q)
4142 if(data[q])
4143 {
4144 screens[scr].data[q] = data[q];
4145 screens[scr].cset[q] = cset[q];
4146 }
4147 }
4148 }
4149
4150 void list_command::execute()
4151 {
4152 for (auto command : commands)
4153 {
4154 command->execute();
4155 }
4156 }
4157
4158 void list_command::undo()
4159 {
4160 for (int i = commands.size() - 1; i >= 0; i--)
4161 {
4162 commands[i]->undo();
4163 }
4164 }
4165
4166 int list_command::size()
4167 {
4168 int s = 0;
4169 for (auto command : commands)
4170 {
4171 s += command->size();
4172 }
4173 return s;
4174 }
4175
4176 void set_combo_command::execute()
4177 {
4178 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4179 if(!mapscr_ptr) return;
4180
4181 mapscr_ptr->valid |= mVALID;
4182 if (combo != -1) mapscr_ptr->data[pos] = combo;
4183 mapscr_ptr->cset[pos] = cset;
4184 }
4185
4186 void set_combo_command::undo()
4187 {
4188 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4189 if(!mapscr_ptr) return;
4190 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4191 mapscr_ptr->cset[pos] = prev_cset;
4192 }
4193
4194 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4195 {
4196 std::array<int, 2> inita_arr;
4197 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4198 std::array<int, 8> initd_arr;
4199 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4200
4201 return {
4202 .x = ffc.x,
4203 .y = ffc.y,
4204 .vx = ffc.vx,
4205 .vy = ffc.vy,
4206 .ax = ffc.ax,
4207 .ay = ffc.ay,
4208 .data = ffc.data,
4209 .cset = ffc.cset,
4210 .delay = ffc.delay,
4211 .link = ffc.link,
4212 .script = ffc.script,
4213 .tw = ffc.txsz,
4214 .th = ffc.tysz,
4215 .ew = ffc.hit_width,
4216 .eh = ffc.hit_height,
4217 .flags = ffc.flags,
4218 .inita = inita_arr,
4219 .initd = initd_arr,
4220 };
4221 }
4222
4223 void set_ffc_command::execute()
4224 {
4225 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4226 if(!mapscr_ptr) return;
4227
4228 mapscr_ptr->valid |= mVALID;
4229 mapscr_ptr->ffcs[i].x = data.x;
4230 mapscr_ptr->ffcs[i].y = data.y;
4231 mapscr_ptr->ffcs[i].vx = data.vx;
4232 mapscr_ptr->ffcs[i].vy = data.vy;
4233 mapscr_ptr->ffcs[i].ax = data.ax;
4234 mapscr_ptr->ffcs[i].ay = data.ay;
4235 mapscr_ptr->ffcs[i].data = data.data;
4236 mapscr_ptr->ffcs[i].cset = data.cset;
4237 mapscr_ptr->ffcs[i].delay = data.delay;
4238 mapscr_ptr->ffcs[i].link = data.link;
4239 mapscr_ptr->ffcs[i].script = data.script;
4240 mapscr_ptr->ffcs[i].flags = data.flags;
4241 mapscr_ptr->ffEffectWidth(i, data.ew);
4242 mapscr_ptr->ffEffectHeight(i, data.eh);
4243 mapscr_ptr->ffTileWidth(i, data.tw);
4244 mapscr_ptr->ffTileHeight(i, data.th);
4245 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4246 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4247 mapscr_ptr->ffcCountMarkDirty();
4248 mapscr_ptr->ffcs[i].updateSolid();
4249 }
4250
4251 void set_ffc_command::undo()
4252 {
4253 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4254 if(!mapscr_ptr) return;
4255
4256 mapscr_ptr->ffcs[i].x = prev_data.x;
4257 mapscr_ptr->ffcs[i].y = prev_data.y;
4258 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4259 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4260 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4261 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4262 mapscr_ptr->ffcs[i].data = prev_data.data;
4263 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4264 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4265 mapscr_ptr->ffcs[i].link = prev_data.link;
4266 mapscr_ptr->ffcs[i].script = prev_data.script;
4267 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4268 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4269 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4270 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4271 mapscr_ptr->ffTileHeight(i, prev_data.th);
4272 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4273 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4274 mapscr_ptr->ffcCountMarkDirty();
4275 mapscr_ptr->ffcs[i].updateSolid();
4276 }
4277
4278 void set_flag_command::execute()
4279 {
4280 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4281 if(!mapscr_ptr) return;
4282
4283 mapscr_ptr->valid |= mVALID;
4284 mapscr_ptr->sflag[pos] = flag;
4285 }
4286
4287 void set_flag_command::undo()
4288 {
4289 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4290 if(!mapscr_ptr) return;
4291 mapscr_ptr->sflag[pos] = prev_flag;
4292 }
4293
4294 void set_door_command::execute()
4295 {
4296 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4297 if(!mapscr_ptr) return;
4298
4299 mapscr_ptr->valid |= mVALID;
4300 mapscr_ptr->door[side] = door;
4301 }
4302
4303 void set_door_command::undo()
4304 {
4305 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4306 }
4307
4308 void set_dcs_command::execute()
4309 {
4310 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4311 if(!mapscr_ptr) return;
4312
4313 mapscr_ptr->valid |= mVALID;
4314 mapscr_ptr->door_combo_set = dcs;
4315 }
4316
4317 void set_dcs_command::undo()
4318 {
4319 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4320 }
4321
4322 void paste_screen_command::execute()
4323 {
4324 perform(screen.get());
4325 }
4326
4327 void paste_screen_command::undo()
4328 {
4329 if (prev_screens.size() > 1)
4330 {
4331 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4332 ASSERT(prev_screens.size() == 128);
4333 for (int i = 0; i < 128; i++)
4334 {
4335 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4336 // TODO: why not just this?
4337 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4338 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4339 }
4340 return;
4341 }
4342
4343 perform(prev_screens[0].get());
4344 }
4345
4346 int paste_screen_command::size()
4347 {
4348 return prev_screens.size() + 1;
4349 }
4350
4351 void paste_screen_command::perform(mapscr* to)
4352 {
4353 if (to)
4354 {
4355 switch (type) {
4356 case ScreenAll: Map.PasteAll(*to); break;
4357 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4358 case ScreenData: Map.PasteScreenData(*to); break;
4359 case ScreenDoors: Map.PasteDoors(*to); break;
4360 case ScreenEnemies: Map.PasteEnemies(*to); break;
4361 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4362 case ScreenGuy: Map.PasteGuy(*to); break;
4363 case ScreenLayers: Map.PasteLayers(*to); break;
4364 case ScreenPalette: Map.PastePalette(*to); break;
4365 case ScreenPartial: Map.Paste(*to); break;
4366 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4367 case ScreenRoom: Map.PasteRoom(*to); break;
4368 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4369 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4370 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4371 case ScreenWarps: Map.PasteWarps(*to); break;
4372 }
4373 }
4374 else
4375 {
4376 Map.clearscr(view_scr);
4377 }
4378 refresh(rALL);
4379 }
4380
4381 void set_screen_command::execute()
4382 {
4383 if (screen)
4384 {
4385 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4386 }
4387 else
4388 {
4389 Map.clearscr(view_scr);
4390 }
4391 refresh(rALL);
4392 }
4393
4394 void set_screen_command::undo()
4395 {
4396 if (prev_screen)
4397 {
4398 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4399 }
4400 else
4401 {
4402 Map.clearscr(view_scr);
4403 }
4404 refresh(rALL);
4405 }
4406
4407 int set_screen_command::size()
4408 {
4409 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4410 }
4411
4412 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4413
4414 void tile_grid_draw_command::execute()
4415 {
4416 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4417 }
4418
4419 void tile_grid_draw_command::undo()
4420 {
4421 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4422 }
4423
4424 static std::shared_ptr<list_command> current_list_command;
4425 void zmap::StartListCommand()
4426 {
4427 ASSERT(!current_list_command);
4428 current_list_command.reset(new list_command);
4429 }
4430
4431 void zmap::FinishListCommand()
4432 {
4433 if (current_list_command->commands.size() == 1)
4434 {
4435 undo_stack.push_back(current_list_command->commands[0]);
4436 }
4437 else if (current_list_command->commands.size() > 1)
4438 {
4439 undo_stack.push_back(current_list_command);
4440 }
4441 CapCommandHistory();
4442 current_list_command = nullptr;
4443 }
4444
4445 void zmap::RevokeListCommand()
4446 {
4447 current_list_command->undo();
4448 current_list_command = nullptr;
4449 }
4450
4451 bool zmap::InListCommand() const
4452 {
4453 return current_list_command ? true : false;
4454 }
4455
4456 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4457 {
4458 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4459 if (!skip_execute) command->execute();
4460 if (current_list_command)
4461 {
4462 current_list_command->commands.push_back(command);
4463 if (current_list_command->commands.size() == 1)
4464 {
4465 current_list_command->view_map = command->view_map;
4466 current_list_command->view_scr = command->view_scr;
4467 }
4468 }
4469 else
4470 {
4471 undo_stack.push_back(command);
4472 CapCommandHistory();
4473 }
4474 saved = false;
4475 }
4476
4477 void zmap::UndoCommand()
4478 {
4479 if (undo_stack.size() <= 0) return;
4480
4481 // If not currently looking at the associated screen, first change the view
4482 // and wait for the next call to actually undo this command.
4483 auto command = undo_stack.back();
4484 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4485 {
4486 setCurrentView(command->view_map, command->view_scr);
4487 return;
4488 }
4489
4490 command->undo();
4491 redo_stack.push(command);
4492 undo_stack.pop_back();
4493 saved = false;
4494 }
4495
4496 void zmap::RedoCommand()
4497 {
4498 if (redo_stack.size() <= 0) return;
4499
4500 // If not currently looking at the associated screen, first change the view
4501 // and wait for the next call to actually execute this command.
4502 auto command = redo_stack.top();
4503 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4504 {
4505 setCurrentView(command->view_map, command->view_scr);
4506 return;
4507 }
4508
4509 command->execute();
4510 undo_stack.push_back(command);
4511 redo_stack.pop();
4512 saved = false;
4513 }
4514
4515 9 void zmap::ClearCommandHistory()
4516 {
4517 9 current_list_command = nullptr;
4518 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4519 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4520 9 }
4521
4522 // Extra amount is from mapscr's vectors.
4523 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4524 // Allow the undo system to use roughly 100 MB of memory.
4525 // This doesn't count the memory used by commands that don't store a mapscr,
4526 // but that should be negligible.
4527 9 static int max_command_size = 100e6 / size_of_mapscr;
4528 void zmap::CapCommandHistory()
4529 {
4530 int size;
4531 do
4532 {
4533 size = 0;
4534 for (auto command : undo_stack)
4535 {
4536 size += command->size();
4537 }
4538 if (size > max_command_size) undo_stack.pop_front();
4539 } while (size > max_command_size);
4540 }
4541
4542 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4543 {
4544 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4545 if(!mapscr_ptr) return;
4546 std::shared_ptr<set_combo_command> command(new set_combo_command);
4547 command->view_map = currmap;
4548 command->view_scr = currscr;
4549 command->map = map;
4550 command->scr = scr;
4551 command->pos = pos;
4552 command->combo = combo;
4553 command->cset = cset;
4554 command->prev_combo = mapscr_ptr->data[pos];
4555 command->prev_cset = mapscr_ptr->cset[pos];
4556 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4557 {
4558 // nothing to do...
4559 return;
4560 }
4561
4562 ExecuteCommand(command);
4563 }
4564
4565 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4566 {
4567 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4568 if(!mapscr_ptr) return;
4569
4570 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4571
4572 std::array<int, 2> inita_arr;
4573 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4574 std::array<int, 8> initd_arr;
4575 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4576
4577 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4578
4579 command->view_map = currmap;
4580 command->view_scr = currscr;
4581 command->map = map;
4582 command->scr = scr;
4583 command->i = i;
4584 command->data = data;
4585 command->prev_data = prev_data;
4586 if (data == prev_data)
4587 {
4588 // nothing to do...
4589 return;
4590 }
4591
4592 ExecuteCommand(command);
4593 }
4594
4595 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4596 {
4597 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4598 if(!mapscr_ptr) return;
4599 std::shared_ptr<set_flag_command> command(new set_flag_command);
4600 command->view_map = currmap;
4601 command->view_scr = currscr;
4602 command->map = map;
4603 command->scr = scr;
4604 command->pos = pos;
4605 command->flag = flag;
4606 command->prev_flag = mapscr_ptr->sflag[pos];
4607 if (command->flag == command->prev_flag)
4608 {
4609 // nothing to do...
4610 return;
4611 }
4612
4613 ExecuteCommand(command);
4614 }
4615
4616 void zmap::DoSetDoorCommand(int scr, int side, int door)
4617 {
4618 if(screens[scr].door[side] == door)
4619 return;
4620 std::shared_ptr<set_door_command> command(new set_door_command);
4621 command->view_map = currmap;
4622 command->view_scr = scr;
4623 command->side = side;
4624 command->door = door;
4625 command->prev_door = screens[scr].door[side];
4626
4627 ExecuteCommand(command);
4628 }
4629 void zmap::DoSetDCSCommand(int dcs)
4630 {
4631 if(screens[currscr].door_combo_set == dcs)
4632 return;
4633 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4634 command->view_map = currmap;
4635 command->view_scr = currscr;
4636 command->dcs = dcs;
4637 command->prev_dcs = screens[currscr].door_combo_set;
4638
4639 ExecuteCommand(command);
4640 }
4641
4642 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4643 {
4644 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4645 command->view_map = currmap;
4646 command->view_scr = currscr;
4647 command->type = type;
4648 command->data = data;
4649 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4650
4651 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4652 {
4653 for (int i=0; i < 128; i++)
4654 {
4655 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4656 }
4657 }
4658 else
4659 {
4660 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4661 }
4662
4663 ExecuteCommand(command);
4664 }
4665
4666 void zmap::DoClearScreenCommand()
4667 {
4668 std::shared_ptr<set_screen_command> command(new set_screen_command);
4669 command->view_map = currmap;
4670 command->view_scr = currscr;
4671 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4672 command->screen = std::shared_ptr<mapscr>(nullptr);
4673
4674 ExecuteCommand(command);
4675 }
4676
4677 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4678 {
4679 std::shared_ptr<set_screen_command> command(new set_screen_command);
4680 command->view_map = currmap;
4681 command->view_scr = currscr;
4682 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4683 Template(floorcombo, floorcset, scr);
4684 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4685
4686 ExecuteCommand(command, true);
4687 }
4688
4689 void zmap::Copy()
4690 {
4691 if(screens[currscr].valid&mVALID)
4692 {
4693 copy_mapscr(&copymapscr, &screens[currscr]);
4694 //copymapscr=screens[currscr];
4695 can_paste=true;
4696 copymap=currmap;
4697 copyscr=currscr;
4698 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4699 copyffc = -1;
4700 }
4701 }
4702
4703 void zmap::CopyFFC(int32_t n)
4704 {
4705 if(screens[currscr].valid&mVALID)
4706 {
4707 copy_mapscr(&copymapscr, &screens[currscr]);
4708 // Can't paste the screen itself
4709 can_paste = false;
4710 copymap=currmap;
4711 copyscr=currscr;
4712 copyffc = n;
4713 }
4714 }
4715
4716 void zmap::Paste(const mapscr& copymapscr)
4717 {
4718 if(can_paste)
4719 {
4720 int32_t oldcolor=getcolor();
4721
4722 if(!(screens[currscr].valid&mVALID))
4723 {
4724 screens[currscr].valid |= mVALID;
4725 screens[currscr].color = copymapscr.color;
4726 }
4727
4728 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4729
4730 for(int32_t i=0; i<4; i++)
4731 {
4732 screens[currscr].door[i]=copymapscr.door[i];
4733 }
4734
4735 for(int32_t i=0; i<176; i++)
4736 {
4737 screens[currscr].data[i] = copymapscr.data[i];
4738 screens[currscr].cset[i] = copymapscr.cset[i];
4739 screens[currscr].sflag[i] = copymapscr.sflag[i];
4740 }
4741
4742 int32_t newcolor=getcolor();
4743 loadlvlpal(newcolor);
4744
4745 if(newcolor!=oldcolor)
4746 {
4747 rebuild_trans_table();
4748 }
4749
4750 saved=false;
4751 }
4752 }
4753
4754 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4755 {
4756 if(can_paste)
4757 {
4758 screens[currscr].undercombo = copymapscr.undercombo;
4759 screens[currscr].undercset = copymapscr.undercset;
4760 saved=false;
4761 }
4762 }
4763
4764 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4765 {
4766 if(can_paste)
4767 {
4768 for(int32_t i=0; i<128; i++)
4769 {
4770 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4771 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4772 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4773 }
4774
4775 saved=false;
4776 }
4777 }
4778
4779 // TODO const mapscr& copymapscr
4780 void zmap::PasteFFCombos(mapscr& copymapscr)
4781 {
4782 if(can_paste)
4783 {
4784 word c = copymapscr.numFFC();
4785 for(word i=0; i<c; i++)
4786 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4787 for(word i = c; i < MAXFFCS; ++i)
4788 screens[currscr].ffcs[i].clear();
4789 screens[currscr].ffcCountMarkDirty();
4790
4791 saved=false;
4792 }
4793 }
4794
4795 void zmap::PasteWarps(const mapscr& copymapscr)
4796 {
4797 if(can_paste)
4798 {
4799 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4800
4801 for(int32_t i=0; i<4; i++)
4802 {
4803 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4804 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4805 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4806 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4807 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4808 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4809 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4810 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4811 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4812 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4813 }
4814
4815 saved=false;
4816 }
4817 }
4818
4819 void zmap::PasteScreenData(const mapscr& copymapscr)
4820 {
4821 if(can_paste)
4822 {
4823 screens[currscr].csensitive = copymapscr.csensitive;
4824 screens[currscr].oceansfx = copymapscr.oceansfx;
4825 screens[currscr].bosssfx = copymapscr.bosssfx;
4826 screens[currscr].secretsfx = copymapscr.secretsfx;
4827 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4828 screens[currscr].flags = copymapscr.flags;
4829 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4830 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4831 screens[currscr].flags3 = copymapscr.flags3;
4832 screens[currscr].flags4 = copymapscr.flags4;
4833 screens[currscr].flags5 = copymapscr.flags5;
4834 screens[currscr].flags6 = copymapscr.flags6;
4835 screens[currscr].flags7 = copymapscr.flags7;
4836 screens[currscr].flags8 = copymapscr.flags8;
4837 screens[currscr].flags9 = copymapscr.flags9;
4838 screens[currscr].flags10 = copymapscr.flags10;
4839 screens[currscr].item = copymapscr.item;
4840 screens[currscr].hasitem = copymapscr.hasitem;
4841 screens[currscr].itemx = copymapscr.itemx;
4842 screens[currscr].itemy = copymapscr.itemy;
4843 screens[currscr].nextmap = copymapscr.nextmap;
4844 screens[currscr].nextscr = copymapscr.nextscr;
4845 screens[currscr].nocarry = copymapscr.nocarry;
4846 screens[currscr].noreset = copymapscr.noreset;
4847 screens[currscr].path[0] = copymapscr.path[0];
4848 screens[currscr].path[1] = copymapscr.path[1];
4849 screens[currscr].path[2] = copymapscr.path[2];
4850 screens[currscr].path[3] = copymapscr.path[3];
4851 screens[currscr].pattern = copymapscr.pattern;
4852 screens[currscr].exitdir = copymapscr.exitdir;
4853 screens[currscr].enemyflags = copymapscr.enemyflags;
4854 screens[currscr].screen_midi = copymapscr.screen_midi;
4855 screens[currscr].stairx = copymapscr.stairx;
4856 screens[currscr].stairy = copymapscr.stairy;
4857 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4858 saved=false;
4859 }
4860 }
4861
4862 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4863 {
4864 if(can_paste)
4865 {
4866 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4867 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4868 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4869
4870 for(int32_t i=0; i<4; i++)
4871 {
4872 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4873 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4874 }
4875
4876 saved=false;
4877 }
4878 }
4879
4880 void zmap::PasteDoors(const mapscr& copymapscr)
4881 {
4882 if(can_paste)
4883 {
4884 for(int32_t i=0; i<4; i++)
4885 screens[currscr].door[i] = copymapscr.door[i];
4886
4887 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4888 saved=false;
4889 }
4890 }
4891
4892 void zmap::PasteLayers(const mapscr& copymapscr)
4893 {
4894 if(can_paste)
4895 {
4896 for(int32_t i=0; i<6; i++)
4897 {
4898 screens[currscr].layermap[i] = copymapscr.layermap[i];
4899 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4900 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4901 }
4902
4903 saved=false;
4904 }
4905 }
4906
4907 void zmap::PasteRoom(const mapscr& copymapscr)
4908 {
4909 if(can_paste)
4910 {
4911 screens[currscr].room = copymapscr.room;
4912 screens[currscr].catchall = copymapscr.catchall;
4913 saved=false;
4914 }
4915 }
4916
4917 void zmap::PasteGuy(const mapscr& copymapscr)
4918 {
4919 if(can_paste)
4920 {
4921 screens[currscr].guy = copymapscr.guy;
4922 screens[currscr].guytile = copymapscr.guytile;
4923 screens[currscr].guycs = copymapscr.guycs;
4924 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4925 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4926 screens[currscr].str = copymapscr.str;
4927 saved=false;
4928 }
4929 }
4930
4931 void zmap::PastePalette(const mapscr& copymapscr)
4932 {
4933 if(can_paste)
4934 {
4935 int32_t oldcolor=getcolor();
4936 screens[currscr].color = copymapscr.color;
4937 int32_t newcolor=getcolor();
4938 loadlvlpal(newcolor);
4939
4940 screens[currscr].valid|=mVALID;
4941
4942 if(newcolor!=oldcolor)
4943 {
4944 rebuild_trans_table();
4945 }
4946
4947 saved=false;
4948 }
4949 }
4950
4951 void zmap::PasteAll(const mapscr& copymapscr)
4952 {
4953 if(can_paste)
4954 {
4955 int32_t oldcolor=getcolor();
4956 copy_mapscr(&screens[currscr], &copymapscr);
4957 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4958 //screens[currscr]=copymapscr;
4959 int32_t newcolor=getcolor();
4960 loadlvlpal(newcolor);
4961
4962 screens[currscr].valid|=mVALID;
4963
4964 if(newcolor!=oldcolor)
4965 {
4966 rebuild_trans_table();
4967 }
4968
4969 saved=false;
4970 }
4971 }
4972
4973
4974 void zmap::PasteToAll(const mapscr& copymapscr)
4975 {
4976 if(can_paste)
4977 {
4978 int32_t oldcolor=getcolor();
4979
4980 for(int32_t x=0; x<128; x++)
4981 {
4982 if(!(screens[x].valid&mVALID))
4983 {
4984 screens[x].valid |= mVALID;
4985 screens[x].color = copymapscr.color;
4986 }
4987
4988 for(int32_t i=0; i<176; i++)
4989 {
4990 screens[x].data[i] = copymapscr.data[i];
4991 screens[x].cset[i] = copymapscr.cset[i];
4992 screens[x].sflag[i] = copymapscr.sflag[i];
4993 }
4994 }
4995
4996 int32_t newcolor=getcolor();
4997 loadlvlpal(newcolor);
4998
4999 if(!(screens[currscr].valid&mVALID))
5000 {
5001 newcolor=-1;
5002 }
5003
5004 if(newcolor!=oldcolor)
5005 {
5006 rebuild_trans_table();
5007 }
5008
5009 saved=false;
5010 }
5011 }
5012
5013 void zmap::PasteAllToAll(const mapscr& copymapscr)
5014 {
5015 if(can_paste)
5016 {
5017 int32_t oldcolor=getcolor();
5018
5019 for(int32_t x=0; x<128; x++)
5020 {
5021 copy_mapscr(&screens[x], &copymapscr);
5022 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5023 //screens[x]=copymapscr;
5024 }
5025
5026 int32_t newcolor=getcolor();
5027 loadlvlpal(newcolor);
5028
5029 if(!(screens[currscr].valid&mVALID))
5030 {
5031 newcolor=-1;
5032 }
5033
5034 if(newcolor!=oldcolor)
5035 {
5036 rebuild_trans_table();
5037 }
5038
5039 saved=false;
5040 }
5041 }
5042
5043 void zmap::PasteEnemies(const mapscr& copymapscr)
5044 {
5045 if(can_paste)
5046 {
5047 for(int32_t i=0; i<10; i++)
5048 screens[currscr].enemy[i]=copymapscr.enemy[i];
5049 }
5050 }
5051
5052 void zmap::setCopyFFC(int32_t n)
5053 {
5054 copyffc = n;
5055 }
5056
5057 void zmap::update_combo_cycling()
5058 {
5059 if(!prv_mode||!prv_cmbcycle)
5060 {
5061 return;
5062 }
5063
5064 int32_t x;
5065 int32_t newdata[176];
5066 int32_t newcset[176];
5067 bool restartanim[MAXCOMBOS] = {0};
5068
5069 for(int32_t i=0; i<176; i++)
5070 {
5071 newdata[i]=-1;
5072 newcset[i]=-1;
5073
5074 x=prvscr.data[i];
5075
5076 //time to restart
5077 if((combobuf[x].aclk>=combobuf[x].speed) &&
5078 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5079 (combobuf[x].nextcombo!=0))
5080 {
5081 newdata[i]=combobuf[x].nextcombo;
5082 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5083 newcset[i]=combobuf[x].nextcset;
5084 int32_t c = newdata[i];
5085
5086 if(combobuf[c].animflags & AF_CYCLE)
5087 {
5088 restartanim[c]=true;
5089 }
5090 }
5091 }
5092
5093 for(int32_t i=0; i<176; i++)
5094 {
5095 x=prvscr.data[i];
5096
5097 //time to restart
5098 if((combobuf[x].aclk>=combobuf[x].speed) &&
5099 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5100 (combobuf[x].nextcombo!=0))
5101 {
5102 newdata[i]=combobuf[x].nextcombo;
5103 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5104 newcset[i]=combobuf[x].nextcset;
5105 int32_t c = newdata[i];
5106
5107 if(combobuf[c].animflags & AF_CYCLE)
5108 {
5109 restartanim[c]=true;
5110 }
5111 }
5112 }
5113
5114 for(int32_t i=0; i<176; i++)
5115 {
5116 if(newdata[i]==-1)
5117 continue;
5118
5119 prvscr.data[i]=newdata[i];
5120 prvscr.cset[i]=newcset[i];
5121 }
5122
5123 word maxffc = prvscr.numFFC();
5124 for(word i=0; i<maxffc; i++)
5125 {
5126 ffcdata& ffc = prvscr.ffcs[i];
5127 newcombo const& cmb = combobuf[ffc.data];
5128
5129 //time to restart
5130 if((cmb.aclk>=cmb.speed) &&
5131 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5132 (cmb.nextcombo!=0))
5133 {
5134 ffc.data = cmb.nextcombo;
5135 if(!(cmb.animflags & AF_CYCLENOCSET))
5136 ffc.cset=cmb.nextcset;
5137
5138 if(combobuf[ffc.data].animflags & AF_CYCLE)
5139 {
5140 restartanim[ffc.data]=true;
5141 }
5142 prvscr.ffcs[i].data = ffc.data;
5143 prvscr.ffcs[i].cset=ffc.cset;
5144 }
5145 }
5146
5147
5148 if(get_qr(qr_CMBCYCLELAYERS))
5149 {
5150 for(int32_t j=0; j<6; j++)
5151 {
5152 if(!prvlayers[j].valid)
5153 continue;
5154
5155 for(int32_t i=0; i<176; i++)
5156 {
5157 newdata[i]=-1;
5158 newcset[i]=-1;
5159
5160 x=(prvlayers[j]).data[i];
5161
5162 //time to restart
5163 if((combobuf[x].aclk>=combobuf[x].speed) &&
5164 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5165 (combobuf[x].nextcombo!=0))
5166 {
5167 newdata[i]=combobuf[x].nextcombo;
5168 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5169 newcset[i]=combobuf[x].nextcset;
5170 int32_t c = newdata[i];
5171
5172 if(combobuf[c].animflags & AF_CYCLE)
5173 {
5174 restartanim[c]=true;
5175 }
5176 }
5177 }
5178
5179 for(int32_t i=0; i<176; i++)
5180 {
5181 x=(prvlayers[j]).data[i];
5182
5183 //time to restart
5184 if((combobuf[x].aclk>=combobuf[x].speed) &&
5185 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5186 (combobuf[x].nextcombo!=0))
5187 {
5188 newdata[i]=combobuf[x].nextcombo;
5189 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5190 newcset[i]=combobuf[x].nextcset;
5191 int32_t c = newdata[i];
5192
5193 if(combobuf[c].animflags & AF_CYCLE)
5194 {
5195 restartanim[c]=true;
5196 }
5197 }
5198 }
5199
5200 for(int32_t i=0; i<176; i++)
5201 {
5202 if(newdata[i]==-1)
5203 continue;
5204
5205 prvlayers[j].data[i]=newdata[i];
5206 prvlayers[j].cset[i]=newcset[i];
5207 }
5208 }
5209 }
5210
5211 for(int32_t i=0; i<MAXCOMBOS; i++)
5212 {
5213 if(restartanim[i])
5214 {
5215 combobuf[i].tile = combobuf[i].o_tile;
5216 combobuf[i].cur_frame=0;
5217 combobuf[i].aclk = 0;
5218 }
5219 }
5220 }
5221
5222 void zmap::update_freeform_combos()
5223 {
5224 if(!prv_mode||!prv_cmbcycle)
5225 {
5226 return;
5227 }
5228
5229 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5230 word maxffc = prvscr.numFFC();
5231 for(int32_t i=0; i<maxffc; i++)
5232 {
5233 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5234 {
5235 for(int32_t j=0; j<maxffc; j++)
5236 {
5237 if(i!=j)
5238 {
5239 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5240 {
5241 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5242 {
5243 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5244 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5245 {
5246 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5247 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5248 if(prvscr.ffcs[j].flags&ffc_changethis)
5249 {
5250 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5251 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5252 }
5253
5254 if(prvscr.ffcs[j].flags&ffc_changenext)
5255 prvscr.ffcs[i].data += 1;
5256
5257 if(prvscr.ffcs[j].flags&ffc_changeprev)
5258 prvscr.ffcs[i].data -= 1;
5259
5260 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5261 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5262 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5263
5264 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5265 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5266 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5267 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5268
5269 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5270 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5271 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5272 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5273 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5274
5275 if(prvscr.ffcs[i].flags&ffc_carryover)
5276 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5277 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5278
5279 prvscr.ffcs[i].flags&=~ffc_changer;
5280 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5281 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5282
5283 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5284 {
5285 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5286 }
5287
5288 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5289 {
5290 int32_t k=0;
5291
5292 if(prvscr.ffcs[j].flags&ffc_swapnext)
5293 k=j<(MAXFFCS-1)?j+1:0;
5294
5295 if(prvscr.ffcs[j].flags&ffc_swapprev)
5296 k=j>0?j-1:(MAXFFCS-1);
5297
5298 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5299 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5300 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5301 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5302 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5303 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5304 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5305 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5306 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5307 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5308 }
5309 }
5310 }
5311 }
5312 }
5313 }
5314
5315 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5316 {
5317 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5318 {
5319 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5320 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5321 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5322 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5323 }
5324 else
5325 {
5326 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5327 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5328 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5329 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5330 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5331 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5332
5333 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5334 {
5335 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5336
5337 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5338
5339 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5340
5341 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5342 }
5343 }
5344 }
5345 else
5346 {
5347 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5348 prvscr.ffcs[i].delay--;
5349 }
5350
5351 if(prvscr.ffcs[i].x<-32)
5352 {
5353 if(prvscr.flags6&fWRAPAROUNDFF)
5354 {
5355 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5356 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5357 }
5358 else
5359 {
5360 prvscr.ffcs[i].data = 0;
5361 prvscr.ffcs[i].flags&=~ffc_carryover;
5362 }
5363 }
5364
5365 if(prvscr.ffcs[i].y<-32)
5366 {
5367 if(prvscr.flags6&fWRAPAROUNDFF)
5368 {
5369 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5370 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5371 }
5372 else
5373 {
5374 prvscr.ffcs[i].data = 0;
5375 prvscr.ffcs[i].flags&=~ffc_carryover;
5376 }
5377 }
5378
5379 if(prvscr.ffcs[i].x>=288)
5380 {
5381 if(prvscr.flags6&fWRAPAROUNDFF)
5382 {
5383 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5384 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5385 }
5386 else
5387 {
5388 prvscr.ffcs[i].data = 0;
5389 prvscr.ffcs[i].flags&=~ffc_carryover;
5390 }
5391 }
5392
5393 if(prvscr.ffcs[i].y>=208)
5394 {
5395 if(prvscr.flags6&fWRAPAROUNDFF)
5396 {
5397 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5398 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5399 }
5400 else
5401 {
5402 prvscr.ffcs[i].data = 0;
5403 prvscr.ffcs[i].flags&=~ffc_carryover;
5404 }
5405 }
5406
5407 }
5408 }
5409 }
5410
5411 void zmap::goto_dmapscr(int dmap, int scr)
5412 {
5413 setCurrMap(DMaps[dmap].map);
5414 setCurrScr(scr+DMaps[dmap].xoff);
5415 }
5416 void zmap::goto_mapscr(int map, int scr)
5417 {
5418 setCurrMap(map);
5419 setCurrScr(scr);
5420 }
5421
5422 void zmap::dowarp(int32_t type, int32_t index)
5423 {
5424 set_warpback();
5425 if(type==0)
5426 {
5427
5428 int32_t dmap=screens[currscr].tilewarpdmap[index];
5429 int32_t scr=screens[currscr].tilewarpscr[index];
5430
5431 switch(screens[currscr].tilewarptype[index])
5432 {
5433 case wtCAVE:
5434 case wtNOWARP:
5435 break;
5436
5437 default:
5438 goto_dmapscr(dmap, scr);
5439 break;
5440 }
5441 }
5442 else if(type==1)
5443 {
5444 int32_t dmap=screens[currscr].sidewarpdmap[index];
5445 int32_t scr=screens[currscr].sidewarpscr[index];
5446
5447 switch(screens[currscr].sidewarptype[index])
5448 {
5449 case wtCAVE:
5450 case wtNOWARP:
5451 break;
5452
5453 default:
5454 goto_dmapscr(dmap, scr);
5455 break;
5456 }
5457 }
5458 }
5459
5460 extern int32_t prv_twon;
5461
5462 void zmap::prv_dowarp(int32_t type, int32_t index)
5463 {
5464 if(type==0)
5465 {
5466
5467 int32_t dmap=prvscr.tilewarpdmap[index];
5468 int32_t scr=prvscr.tilewarpscr[index];
5469
5470 switch(prvscr.tilewarptype[index])
5471 {
5472 case wtCAVE:
5473 case wtNOWARP:
5474 break;
5475
5476 default:
5477 //setCurrMap(DMaps[dmap].map);
5478 //setCurrScr(scr+DMaps[dmap].xoff);
5479 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5480 loadlvlpal(getcolor());
5481 rebuild_trans_table();
5482 //prv_cmbcycle=0;
5483 break;
5484 }
5485 }
5486 else if(type==1)
5487 {
5488 int32_t dmap=prvscr.sidewarpdmap[index];
5489 int32_t scr=prvscr.sidewarpscr[index];
5490
5491 switch(prvscr.sidewarptype[index])
5492 {
5493 case wtCAVE:
5494 case wtNOWARP:
5495 break;
5496
5497 default:
5498 //setCurrMap(DMaps[dmap].map);
5499 //setCurrScr(scr+DMaps[dmap].xoff);
5500 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5501 loadlvlpal(getcolor());
5502 rebuild_trans_table();
5503 //prv_cmbcycle=0;
5504 break;
5505 }
5506 }
5507
5508 if(prv_twon)
5509 {
5510 prv_time=get_prvscr()->timedwarptics;
5511 }
5512
5513 //also reset FFC information (so that changers will work correctly) -DD
5514 memset(ffposx,0xFF,sizeof(int16_t)*32);
5515 memset(ffposy,0xFF,sizeof(int16_t)*32);
5516 memset(ffprvx,0xFF,sizeof(float)*32);
5517 memset(ffprvy,0xFF,sizeof(float)*32);
5518 }
5519
5520 void zmap::dowarp2(int32_t ring,int32_t index)
5521 {
5522 set_warpback();
5523 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5524 }
5525
5526 void zmap::set_warpback()
5527 {
5528 warpbackmap = currmap;
5529 warpbackscreen = currscr;
5530 }
5531 bool zmap::has_warpback()
5532 {
5533 return warpbackmap && warpbackscreen
5534 && !(warpbackmap == currmap && warpbackscreen == currscr);
5535 }
5536 void zmap::warpback()
5537 {
5538 if(!has_warpback())
5539 return;
5540 int m = currmap, s = currscr;
5541 goto_mapscr(*warpbackmap, *warpbackscreen);
5542 warpbackmap = m;
5543 warpbackscreen = s;
5544 }
5545
5546 bool save_msgstrs(const char *path)
5547 {
5548 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5549
5550 if(!f)
5551 {
5552 return false;
5553 }
5554
5555 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5556 {
5557 pack_fclose(f);
5558 return true;
5559 }
5560
5561 pack_fclose(f);
5562 return false;
5563 }
5564
5565 1 bool save_strings_tsv(const char *path)
5566 {
5567 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5568
5569
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5570 {
5571 return false;
5572 }
5573
5574
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5575 {
5576 1 pack_fclose(f);
5577 1 return true;
5578 }
5579
5580 pack_fclose(f);
5581 return false;
5582 1 }
5583
5584 bool save_msgstrs_text(const char *path)
5585 {
5586 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5587
5588 if(!f)
5589 {
5590 return false;
5591 }
5592
5593 if(writestrings_text(f)==0)
5594 {
5595 pack_fclose(f);
5596 return true;
5597 }
5598
5599 pack_fclose(f);
5600 return false;
5601 }
5602
5603 bool load_msgstrs(const char *path, int32_t startstring)
5604 {
5605 //these are here to bypass compiler warnings about unused arguments
5606 startstring=startstring;
5607
5608 dword section_id;
5609 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5610
5611 if(!f)
5612 {
5613 return false;
5614 }
5615
5616 if(!p_mgetl(&section_id,f))
5617 {
5618 return false;
5619 }
5620
5621 if(section_id==ID_STRINGS)
5622 {
5623 if(readstrings(f, &header)==0)
5624 {
5625 pack_fclose(f);
5626 return true;
5627 }
5628 else
5629 {
5630 pack_fclose(f);
5631 return false;
5632 }
5633 }
5634
5635 pack_fclose(f);
5636 return false;
5637 }
5638
5639 bool load_strings_tsv(const char *path)
5640 {
5641 try
5642 {
5643 parse_strings_tsv(util::read_text_file(path));
5644 }
5645 catch (std::exception& ex)
5646 {
5647 InfoDialog("Import .tsv Error", ex.what()).show();
5648 return false;
5649 }
5650 return true;
5651 }
5652
5653 bool save_pals(const char *path)
5654 {
5655 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5656
5657 if(!f)
5658 {
5659 return false;
5660 }
5661
5662 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5663 {
5664 pack_fclose(f);
5665 return true;
5666 }
5667
5668 pack_fclose(f);
5669 return false;
5670 }
5671
5672 bool load_pals(const char *path, int32_t startcset)
5673 {
5674 dword section_id;
5675 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5676
5677 if(!f)
5678 {
5679 return false;
5680 }
5681
5682 if(!p_mgetl(&section_id,f))
5683 {
5684 return false;
5685 }
5686
5687 if(section_id==ID_CSETS)
5688 {
5689 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5690 {
5691 pack_fclose(f);
5692 loadlvlpal(Color);
5693 return true;
5694 }
5695 else
5696 {
5697 pack_fclose(f);
5698 return false;
5699 }
5700 }
5701
5702 return false;
5703 }
5704
5705 bool save_dmaps(const char *path)
5706 {
5707 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5708
5709 if(!f)
5710 {
5711 return false;
5712 }
5713
5714 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5715 {
5716 pack_fclose(f);
5717 return true;
5718 }
5719
5720 pack_fclose(f);
5721 return false;
5722 }
5723
5724 bool load_dmaps(const char *path, int32_t startdmap)
5725 {
5726 dword section_id;
5727 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5728
5729 if(!f)
5730 {
5731 return false;
5732 }
5733
5734 if(!p_mgetl(&section_id,f))
5735 {
5736 return false;
5737 }
5738
5739 if(section_id==ID_DMAPS)
5740 {
5741 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5742 {
5743 pack_fclose(f);
5744 return true;
5745 }
5746 else
5747 {
5748 pack_fclose(f);
5749 return false;
5750 }
5751 }
5752
5753 return false;
5754 }
5755 bool save_combos(const char *path)
5756 {
5757 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5758
5759 if(!f)
5760 {
5761 return false;
5762 }
5763
5764 reset_combo_animations();
5765 reset_combo_animations2();
5766
5767 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5768 {
5769 pack_fclose(f);
5770 return true;
5771 }
5772
5773 pack_fclose(f);
5774 return false;
5775 }
5776
5777 bool load_combos(const char *path, int32_t startcombo)
5778 {
5779 dword section_id;
5780 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5781
5782 if(!f)
5783 {
5784 return false;
5785 }
5786
5787 if(!p_mgetl(&section_id,f))
5788 {
5789 return false;
5790 }
5791
5792 if(section_id==ID_COMBOS)
5793 {
5794 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5795 {
5796 pack_fclose(f);
5797 return true;
5798 }
5799 else
5800 {
5801 pack_fclose(f);
5802 return false;
5803 }
5804 }
5805
5806 return false;
5807 }
5808
5809 bool save_tiles(const char *path)
5810 {
5811 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5812
5813 if(!f)
5814 {
5815 return false;
5816 }
5817
5818 // reset_combo_animations();
5819 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5820 {
5821 pack_fclose(f);
5822 return true;
5823 }
5824
5825 pack_fclose(f);
5826 return false;
5827 }
5828
5829 bool load_tiles(const char *path, int32_t starttile)
5830 {
5831 dword section_id;
5832 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5833
5834 if(!f)
5835 {
5836 return false;
5837 }
5838
5839 if(!p_mgetl(&section_id,f))
5840 {
5841 return false;
5842 }
5843
5844 if(section_id==ID_TILES)
5845 {
5846 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5847 {
5848 pack_fclose(f);
5849 return true;
5850 }
5851 else
5852 {
5853 pack_fclose(f);
5854 init_tiles(true, &header);
5855 return false;
5856 }
5857 }
5858
5859 return false;
5860 }
5861
5862 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5863 bool save_guys(const char *path)
5864 {
5865 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5866
5867 if(!f)
5868 {
5869 return false;
5870 }
5871
5872 /*
5873 int32_t id = ID_GUYS;
5874 if(!p_mputl(id,f))
5875 {
5876 return false;
5877 }
5878 */
5879
5880 zquestheader h;
5881 h.zelda_version = 0x250;
5882 h.build = 21;
5883
5884 if(writeguys(f, &h)==0)
5885 {
5886 pack_fclose(f);
5887 return true;
5888 }
5889
5890 pack_fclose(f);
5891 return false;
5892 }
5893
5894 bool load_guys(const char *path)
5895 {
5896 dword section_id;
5897 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5898
5899 if(!f)
5900 {
5901 return false;
5902 }
5903
5904 if(!p_mgetl(&section_id,f))
5905 {
5906 pack_fclose(f);
5907 return false;
5908 }
5909
5910 zquestheader h;
5911 h.zelda_version = 0x250;
5912 h.build = 21;
5913
5914 if(section_id==ID_GUYS)
5915 {
5916 if(readguys(f, &h)==0)
5917 {
5918 pack_fclose(f);
5919 return true;
5920 }
5921 }
5922
5923 pack_fclose(f);
5924 return false;
5925 }
5926
5927
5928 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5929 bool save_combo_alias(const char *path)
5930 {
5931 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5932
5933 if(!f)
5934 {
5935 return false;
5936 }
5937
5938 zquestheader h;
5939 h.zelda_version = 0x250;
5940 h.build = 21;
5941
5942 if(writecomboaliases(f, 0, 0)==0)
5943 {
5944 pack_fclose(f);
5945 return true;
5946 }
5947
5948 pack_fclose(f);
5949 return false;
5950 }
5951
5952 bool load_combo_alias(const char *path)
5953 {
5954 dword section_id;
5955 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5956
5957 if(!f)
5958 {
5959 return false;
5960 }
5961
5962 if(!p_mgetl(&section_id,f))
5963 {
5964 pack_fclose(f);
5965 return false;
5966 }
5967
5968 zquestheader h;
5969 h.zelda_version = 0x250;
5970 h.build = 21;
5971
5972 if(section_id==ID_COMBOALIASES)
5973 {
5974 if(readcomboaliases(f, &h, 0, 0)==0)
5975 {
5976 pack_fclose(f);
5977 return true;
5978 }
5979 }
5980
5981 pack_fclose(f);
5982 return false;
5983 }
5984
5985 bool load_zgp(const char *path)
5986 {
5987 dword section_id;
5988 dword section_version;
5989 dword section_cversion;
5990 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5991
5992 if(!f)
5993 return false;
5994
5995 if(!p_mgetl(&section_id,f))
5996 {
5997 pack_fclose(f);
5998 return false;
5999 }
6000
6001 if(section_id!=ID_GRAPHICSPACK)
6002 {
6003 pack_fclose(f);
6004 return false;
6005 }
6006
6007 //section version info
6008 if(!p_igetw(&section_version,f))
6009 {
6010 return 2;
6011 }
6012
6013 if(!p_igetw(&section_cversion,f))
6014 {
6015 return 3;
6016 }
6017
6018 //tiles
6019 if(!p_mgetl(&section_id,f))
6020 {
6021 pack_fclose(f);
6022 return false;
6023 }
6024
6025 if(section_id==ID_TILES)
6026 {
6027 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6028 {
6029 pack_fclose(f);
6030 init_tiles(true, &header);
6031 return false;
6032 }
6033 }
6034 else
6035 {
6036 pack_fclose(f);
6037 return false;
6038 }
6039
6040 //combos
6041 if(!p_mgetl(&section_id,f))
6042 {
6043 pack_fclose(f);
6044 return false;
6045 }
6046
6047 if(section_id==ID_COMBOS)
6048 {
6049 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6050 {
6051 pack_fclose(f);
6052 return false;
6053 }
6054 }
6055 else
6056 {
6057 pack_fclose(f);
6058 return false;
6059 }
6060
6061 //palettes
6062 if(!p_mgetl(&section_id,f))
6063 {
6064 pack_fclose(f);
6065 return false;
6066 }
6067
6068 if(section_id==ID_CSETS)
6069 {
6070 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6071 {
6072 pack_fclose(f);
6073 return false;
6074 }
6075 }
6076 else
6077 {
6078 pack_fclose(f);
6079 return false;
6080 }
6081
6082 //items
6083 if(!p_mgetl(&section_id,f))
6084 {
6085 pack_fclose(f);
6086 return false;
6087 }
6088
6089 if(section_id==ID_ITEMS)
6090 {
6091 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6092 {
6093 pack_fclose(f);
6094 return false;
6095 }
6096 }
6097 else
6098 {
6099 pack_fclose(f);
6100 return false;
6101 }
6102
6103 //weapons
6104 if(!p_mgetl(&section_id,f))
6105 {
6106 pack_fclose(f);
6107 return false;
6108 }
6109
6110 if(section_id==ID_WEAPONS)
6111 {
6112 if(readweapons(f, &header)!=0)
6113 {
6114 pack_fclose(f);
6115 return false;
6116 }
6117 }
6118 else
6119 {
6120 pack_fclose(f);
6121 return false;
6122 }
6123
6124 //read the triforce pieces info and make sure it worked
6125 //really do this?
6126
6127 //read the game icons info and make sure it worked
6128 if(!p_mgetl(&section_id,f))
6129 {
6130 pack_fclose(f);
6131 return false;
6132 }
6133
6134 if(section_id==ID_ICONS)
6135 {
6136 if(readgameicons(f, &header, &QMisc)!=0)
6137 {
6138 pack_fclose(f);
6139 return false;
6140 }
6141 }
6142 else
6143 {
6144 pack_fclose(f);
6145 return false;
6146 }
6147
6148 //read the misc colors info and map styles info and make sure it worked
6149 if(!p_mgetl(&section_id,f))
6150 {
6151 pack_fclose(f);
6152 return false;
6153 }
6154
6155 if(section_id==ID_COLORS)
6156 {
6157 if(readmisccolors(f, &header, &QMisc)!=0)
6158 {
6159 pack_fclose(f);
6160 return false;
6161 }
6162 }
6163 else
6164 {
6165 pack_fclose(f);
6166 return false;
6167 }
6168
6169 //read the door combo sets and make sure it worked
6170 if(!p_mgetl(&section_id,f))
6171 {
6172 pack_fclose(f);
6173 return false;
6174 }
6175
6176 if(section_id==ID_DOORS)
6177 {
6178 if(readdoorcombosets(f, &header)!=0)
6179 {
6180 pack_fclose(f);
6181 return false;
6182 }
6183 }
6184 else
6185 {
6186 pack_fclose(f);
6187 return false;
6188 }
6189
6190 //read the template screens and make sure it worked
6191 //really do this?
6192
6193 //yay! it worked! close the file and say everything was ok.
6194 loadlvlpal(Color);
6195 setup_combo_animations();
6196 setup_combo_animations2();
6197 pack_fclose(f);
6198 return true;
6199 }
6200
6201 bool save_zgp(const char *path)
6202 {
6203 reset_combo_animations();
6204 reset_combo_animations2();
6205
6206 //open the file
6207 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6208
6209 if(!f)
6210 return false;
6211
6212 dword section_id=ID_GRAPHICSPACK;
6213 dword section_version=V_GRAPHICSPACK;
6214 dword section_cversion=CV_GRAPHICSPACK;
6215
6216 //section id
6217 if(!p_mputl(section_id,f))
6218 {
6219 return 1;
6220 }
6221
6222 //section version info
6223 if(!p_iputw(section_version,f))
6224 {
6225 return 2;
6226 }
6227
6228 if(!p_iputw(section_cversion,f))
6229 {
6230 return 3;
6231 }
6232
6233 //tiles
6234 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6235 {
6236 pack_fclose(f);
6237 return false;
6238 }
6239
6240 //combos
6241 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6242 {
6243 pack_fclose(f);
6244 return false;
6245 }
6246
6247 //palettes
6248 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6249 {
6250 pack_fclose(f);
6251 return false;
6252 }
6253
6254 //items
6255 if(writeitems(f, &header)!=0)
6256 {
6257 pack_fclose(f);
6258 return false;
6259 }
6260
6261 //weapons
6262 if(writeweapons(f, &header)!=0)
6263 {
6264 pack_fclose(f);
6265 return false;
6266 }
6267
6268 //write the triforce pieces info and make sure it worked
6269 //really do this?
6270
6271 //write the game icons info and make sure it worked
6272 if(writegameicons(f, &header)!=0)
6273 {
6274 pack_fclose(f);
6275 return false;
6276 }
6277
6278 //write the misc colors info and map styles info and make sure it worked
6279 if(writemisccolors(f, &header)!=0)
6280 {
6281 pack_fclose(f);
6282 return false;
6283 }
6284
6285 //write the door combo sets and make sure it worked
6286 if(writedoorcombosets(f, &header)!=0)
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291
6292 //write the template screens and make sure it worked
6293 //really do this?
6294
6295 pack_fclose(f);
6296 return true;
6297 }
6298
6299 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6300 {
6301 //open the file
6302 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6303
6304 if(!f)
6305 return false;
6306
6307 dword section_id=ID_SUBSCREEN;
6308 dword s_version=V_SUBSCREEN;
6309 dword s_cversion=CV_SUBSCREEN;
6310
6311 if(!p_mputl(section_id,f))
6312 {
6313 pack_fclose(f);
6314 return false;
6315 }
6316
6317 if(!p_iputw(s_version,f))
6318 {
6319 pack_fclose(f);
6320 return false;
6321 }
6322
6323 if(!p_iputw(s_cversion,f))
6324 {
6325 pack_fclose(f);
6326 return false;
6327 }
6328
6329 if(savefrom.write(f))
6330 {
6331 pack_fclose(f);
6332 return false;
6333 }
6334
6335 pack_fclose(f);
6336 return true;
6337 }
6338
6339 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6340 {
6341 //open the file
6342 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6343
6344 if(!f)
6345 return false;
6346
6347 dword section_id;
6348 dword s_version;
6349 dword s_cversion;
6350
6351 if(!p_mgetl(&section_id,f))
6352 {
6353 pack_fclose(f);
6354 return false;
6355 }
6356
6357 if(section_id!=ID_SUBSCREEN)
6358 {
6359 pack_fclose(f);
6360 return false;
6361 }
6362
6363 if(!p_igetw(&s_version,f))
6364 {
6365 pack_fclose(f);
6366 return false;
6367 }
6368
6369 if(!p_igetw(&s_cversion,f))
6370 {
6371 pack_fclose(f);
6372 return false;
6373 }
6374
6375 if(s_version < 8)
6376 {
6377 subscreen_group g;
6378 memset(&g,0,sizeof(subscreen_group));
6379 if(read_one_old_subscreen(f,&g,s_version)!=0)
6380 {
6381 pack_fclose(f);
6382 return false;
6383 }
6384 if(g.ss_type != loadto.sub_type)
6385 {
6386 pack_fclose(f);
6387 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6388 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6389 return false;
6390 }
6391 loadto.clear();
6392 if(g.objects[0].type != ssoNULL)
6393 loadto.load_old(g);
6394 }
6395 else
6396 {
6397 ZCSubscreen tmp = ZCSubscreen();
6398 if (tmp.read(f, s_version))
6399 {
6400 pack_fclose(f);
6401 return false;
6402 }
6403 if(tmp.sub_type != loadto.sub_type)
6404 {
6405 pack_fclose(f);
6406 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6407 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6408 return false;
6409 }
6410 loadto.clear();
6411 loadto = tmp;
6412 }
6413
6414 pack_fclose(f);
6415 return true;
6416 }
6417
6418 bool setMapCount2(int32_t c)
6419 {
6420 int32_t oldmapcount=map_count;
6421 int32_t currmap=Map.getCurrMap();
6422
6423 bound(c,1,MAXMAPS);
6424 map_count=c;
6425
6426 try
6427 {
6428 TheMaps.resize(c*MAPSCRS);
6429 Map.force_refr_pointer();
6430 map_autolayers.resize(c*6);
6431 }
6432 catch(...)
6433 {
6434 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6435 return false;
6436 }
6437
6438 bound(currmap,0,c-1);
6439 if(map_count>oldmapcount)
6440 {
6441 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6442 {
6443 Map.setCurrMap(mc);
6444
6445 for(int32_t ms=0; ms<MAPSCRS; ms++)
6446 {
6447 Map.clearscr(ms);
6448 }
6449 }
6450 Map.setCurrMap(currmap);
6451 }
6452 else
6453 {
6454 Map.setCurrMap(currmap);
6455 if(!layers_valid(Map.CurrScr()))
6456 fix_layers(Map.CurrScr(), false);
6457
6458 for(int32_t i=0; i<MAXDMAPS; i++)
6459 {
6460 if(DMaps[i].map>=map_count)
6461 {
6462 DMaps[i].map=map_count-1;
6463 }
6464 }
6465 }
6466
6467 return true;
6468 }
6469
6470 extern BITMAP *bmap;
6471
6472 static bool loading_file_new = false;
6473 1 int32_t init_quest()
6474 {
6475 char qstdat_string[2048];
6476 1 strcpy(qstdat_string, "modules/classic/default.qst");
6477
6478 char buf[2048];
6479
6480 1 loading_file_new = true;
6481 1 load_quest(qstdat_string);
6482 1 loading_file_new = false;
6483
6484 1 sprintf(buf,"ZC Editor - Untitled Quest");
6485 1 set_window_title(buf);
6486 1 zinit.last_map = 0;
6487 1 zinit.last_screen = 0;
6488
6489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6490 {
6491 destroy_bitmap(bmap);
6492 bmap=NULL;
6493 }
6494
6495 1 return 0;
6496 }
6497
6498 void set_questpwd(std::string_view pwd, bool use_keyfile)
6499 {
6500 header.use_keyfile=use_keyfile;
6501
6502 // string_view actually has some quirks that make it less than ideal here.
6503 // It'd probably be best to replace it, but this works for now.
6504 memset(header.password, 0, 256);
6505 strcpy(header.password, pwd.data());
6506 header.dirty_password=true;
6507
6508 cvs_MD5Context ctx;
6509 cvs_MD5Init(&ctx);
6510 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6511 cvs_MD5Final(header.pwd_hash, &ctx);
6512 }
6513
6514
6515 bool is_null_pwd_hash(uint8_t *pwd_hash)
6516 {
6517 cvs_MD5Context ctx;
6518 uint8_t md5sum[16];
6519 char pwd[2]="";
6520
6521 cvs_MD5Init(&ctx);
6522 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6523 cvs_MD5Final(md5sum, &ctx);
6524
6525 return (memcmp(md5sum,pwd_hash,16)==0);
6526 }
6527
6528 static DIALOG pwd_dlg[] =
6529 {
6530 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6531 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6532 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6533 // 2 (filename)
6534 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6535 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6536 // 4 (challenge hash)
6537 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6538 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6539 // 6 (password)
6540 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6541 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6542 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6543 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6544 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6545 };
6546
6547 int32_t reverse_string(char* str)
6548 {
6549
6550 if(NULL==str)
6551 {
6552 return -1; //no string
6553 }
6554
6555 int32_t l=(int32_t)strlen(str)-1; //get the string length
6556
6557 if(1==l)
6558 {
6559 return 1;
6560 }
6561
6562 char c;
6563
6564 for(int32_t x=0; x < l; x++,l--)
6565 {
6566 c = str[x];
6567 str[x] = str[l];
6568 str[l] = c;
6569 }
6570
6571 return 0;
6572 }
6573
6574 #ifdef __GNUC__
6575 #pragma GCC diagnostic push
6576 #pragma GCC diagnostic ignored "-Wunreachable-code"
6577 #endif
6578
6579 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6580 {
6581
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6582 9 return 1;
6583
6584 #ifdef __EMSCRIPTEN__
6585 return 1;
6586 #endif
6587
6588 //Protection against compiling a release version with password protection off.
6589 static bool passguard = false;
6590
6591 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6592 #define MUST_HAVE_PASSWORD
6593 passguard = true;
6594 #endif
6595
6596 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6597 #if (defined _MSC_VER || defined _NPASS)
6598 return 1;
6599 #endif
6600 #endif
6601 if(devpwd()) return 1;
6602
6603 char hash_string[33];
6604
6605 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6606 {
6607 return 1;
6608 }
6609
6610 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6611 return true;
6612
6613 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6614 pwd_dlg[2].dp=get_filename(filename);
6615 cvs_MD5Context ctx;
6616 uint8_t md5sum[16]={0};
6617 char response[33]="";
6618 char prompt[256]="";
6619
6620 memcpy(md5sum, hdr->pwd_hash, 16);
6621
6622 for(int32_t i=0; i<300; ++i)
6623 {
6624 for(int32_t j=0; j<16; ++j)
6625 {
6626 sprintf(response+j*2, "%02x", md5sum[j]);
6627 }
6628
6629 if(i&1)
6630 {
6631 reverse_string(response);
6632 }
6633
6634 if(i==149)
6635 {
6636 strcpy(hash_string, response);
6637 }
6638
6639 cvs_MD5Init(&ctx);
6640 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6641 cvs_MD5Final(md5sum, &ctx);
6642 }
6643
6644 pwd_dlg[4].dp=hash_string;
6645
6646 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6647 {
6648 sprintf(prompt,"%s",response);
6649 }
6650
6651 pwd_dlg[6].dp=prompt;
6652
6653 large_dialog(pwd_dlg);
6654
6655 int32_t cancel = do_zqdialog(pwd_dlg,6);
6656
6657 if(cancel == 8)
6658 return 2;
6659
6660 bool ret=check_questpwd(hdr, prompt);
6661
6662 if(!ret)
6663 {
6664 ret=(strcmp(response,prompt)==0);
6665 }
6666 return ret ? 1 : 0;
6667 9 }
6668
6669 void set_rules(byte* newrules);
6670 8 void popup_bugfix_dlg(const char* cfg)
6671 {
6672 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6673
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6674 {
6675
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6676
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6677 "\nWould you like to apply them?"
6678 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6679 8 [&](bool ret,bool dsa)
6680 {
6681 if(ret)
6682 {
6683 applyRuleTemplate(ruletemplateFixCompat);
6684 }
6685 if(dsa)
6686 {
6687 zc_set_config("zquest",cfg,1);
6688 }
6689 },
6690
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6691 0,false, //timeout - none
6692 true //"Don't show this again"
6693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6694 8 }
6695 8 }
6696
6697 #ifdef __GNUC__
6698 #pragma GCC diagnostic pop
6699 #endif
6700
6701 // wrapper to reinitialize everything on an error
6702 9 int32_t load_quest(const char *filename, bool show_progress)
6703 {
6704 char buf[2048];
6705 // if(encrypted)
6706 // setPackfilePassword(datapwd);
6707 byte skip_flags[4];
6708
6709
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6710 {
6711 36 skip_flags[i]=0;
6712 36 }
6713
2/2
✓ Branch 0 taken 6219 times.
✓ Branch 1 taken 9 times.
6228 for(int32_t i=0; i<qr_MAX; i++)
6714 6219 set_qr(i,0);
6715 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6716
6717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6718 {
6719 init_quest();
6720 }
6721 else
6722 {
6723 9 int32_t accessret = quest_access(filename, &header);
6724
6725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6726 {
6727 init_quest();
6728
6729 if(accessret == 0)
6730 ret=qe_pwd;
6731 else
6732 ret=qe_cancel;
6733 }
6734 else
6735 {
6736 9 Map.clear();
6737 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6738 9 Map.setCurrScr(zinit.last_screen);
6739 extern int32_t current_mappage;
6740 9 current_mappage = 0;
6741 9 bool found_default = false;
6742
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6743 {
6744 65 auto &pg = map_page[q];
6745
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6746 {
6747 2 current_mappage = q;
6748 2 break;
6749 }
6750
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6751 56 continue;
6752 else
6753 {
6754 7 current_mappage = q;
6755 7 found_default = true;
6756 }
6757 7 }
6758 9 refresh(rALL);
6759 9 refresh_pal();
6760 9 set_rules(quest_rules);
6761 9 saved = true;
6762
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6763 8 popup_bugfix_dlg("dsa_compatrule");
6764
6765
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6766 {
6767 destroy_bitmap(bmap);
6768 bmap=NULL;
6769 }
6770
6771
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6772 {
6773 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6774 1 set_window_title(buf);
6775 1 }
6776 }
6777 }
6778
6779 9 Map.ClearCommandHistory();
6780
6781 9 return ret;
6782 }
6783
6784 int32_t load_tileset(const char *filename, dword tsetflags)
6785 {
6786 char buf[2048];
6787 byte skip_flags[4];
6788
6789 for(int32_t i=0; i<4; ++i)
6790 skip_flags[i]=0;
6791 for(int32_t i=0; i<qr_MAX; i++)
6792 set_qr(i,0);
6793 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6794
6795 if(ret!=qe_OK)
6796 init_quest();
6797 else
6798 {
6799 int32_t accessret = quest_access(filename, &header);
6800
6801 if(accessret != 1)
6802 {
6803 init_quest();
6804
6805 if(accessret == 0)
6806 ret=qe_pwd;
6807 else
6808 ret=qe_cancel;
6809 }
6810 else
6811 {
6812 Map.clear();
6813 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6814 Map.setCurrScr(zinit.last_screen);
6815 extern int32_t current_mappage;
6816 current_mappage = 0;
6817 bool found_default = false;
6818 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6819 {
6820 auto &pg = map_page[q];
6821 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6822 {
6823 current_mappage = q;
6824 break;
6825 }
6826 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6827 continue;
6828 else
6829 {
6830 current_mappage = q;
6831 found_default = true;
6832 }
6833 }
6834 refresh(rALL);
6835 refresh_pal();
6836 set_rules(quest_rules);
6837 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6838 popup_bugfix_dlg("dsa_compatrule");
6839
6840 if(bmap != NULL)
6841 {
6842 destroy_bitmap(bmap);
6843 bmap=NULL;
6844 }
6845
6846 set_window_title("ZC Editor - Untitled Quest");
6847 first_save = saved = false;
6848 memset(filepath,0,255);
6849 memset(temppath,0,255);
6850 }
6851 }
6852
6853 Map.ClearCommandHistory();
6854
6855 return ret;
6856 }
6857
6858 60 bool write_midi(MIDI *m,PACKFILE *f)
6859 {
6860 int32_t c;
6861
6862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6863
6864
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6865 {
6866
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6867
6868
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6869 {
6870
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6871 return false;
6872 492 }
6873 1920 }
6874
6875 60 return true;
6876 60 }
6877
6878 bool write_music(int32_t format, MIDI* m, PACKFILE *f)
6879 {
6880 // format - data format (midi, nsf, ...)
6881 // m - pointer to data.
6882
6883 int32_t c;
6884
6885 switch(format)
6886 {
6887 case MFORMAT_MIDI:
6888
6889 if(!p_mputw(m->divisions,f)) return false;
6890
6891 for(c=0; c<MIDI_TRACKS; c++)
6892 {
6893 if(!p_mputl(m->track[c].len,f)) return false;
6894
6895 if(m->track[c].len > 0)
6896 {
6897 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6898 return false;
6899 }
6900 }
6901
6902 break;
6903
6904 case MFORMAT_NSF:
6905
6906 break;
6907
6908 default:
6909 return false;
6910 break;
6911 }
6912
6913 return true;
6914 }
6915
6916 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6917 {
6918 6 dword section_id=ID_HEADER;
6919 6 dword section_version=V_HEADER;
6920 6 dword section_cversion=CV_HEADER;
6921 6 dword section_size=0;
6922
6923 //file header string
6924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6925 {
6926 new_return(1);
6927 }
6928
6929 //section id
6930
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6931 {
6932 new_return(2);
6933 }
6934
6935 //section version info
6936
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6937 {
6938 new_return(3);
6939 }
6940
6941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6942 {
6943 new_return(4);
6944 }
6945
6946
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6947 {
6948 12 fake_pack_writing=(writecycle==0);
6949
6950 //section size
6951
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6952 {
6953 new_return(5);
6954 }
6955
6956 12 writesize=0;
6957
6958 //finally... section data
6959
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6960 {
6961 new_return(6);
6962 }
6963
6964
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6965 {
6966 new_return(7);
6967 }
6968
6969
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6970 {
6971 new_return(8);
6972 }
6973
6974
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6975 {
6976 new_return(10);
6977 }
6978
6979
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6980 {
6981 new_return(11);
6982 }
6983
6984
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6985 {
6986 new_return(12);
6987 }
6988
6989
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6990 {
6991 new_return(13);
6992 }
6993
6994
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6995 {
6996 new_return(14);
6997 }
6998
6999
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
7000 {
7001 new_return(15);
7002 }
7003
7004
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
7005 {
7006 new_return(16);
7007 }
7008
7009
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
7010 {
7011 new_return(17);
7012 }
7013
7014
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
7015 {
7016 new_return(19);
7017 }
7018
7019
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
7020 //this is for map count, it seems. -Z
7021 {
7022 new_return(20);
7023 }
7024
7025 12 auto version = getVersion();
7026
7027
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
7028 {
7029 new_return(21);
7030 }
7031
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
7032 {
7033 new_return(22);
7034 }
7035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
7036 {
7037 new_return(23);
7038 }
7039 // Fourth component is deprecated.
7040
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7041 {
7042 new_return(24);
7043 }
7044
7045 // Numerous prerelease stages is deprecated.
7046
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7047 {
7048 new_return(25);
7049 }
7050
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7051 {
7052 new_return(26);
7053 }
7054
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7055 {
7056 new_return(27);
7057 }
7058
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7059 {
7060 new_return(28);
7061 }
7062
7063
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7064 {
7065 new_return(29);
7066 }
7067
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7068 {
7069 new_return(30);
7070 }
7071
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7072 {
7073 new_return(31);
7074 }
7075
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7076 {
7077 new_return(32);
7078 }
7079
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7080 {
7081 new_return(33);
7082 }
7083
7084
7085
7086 char tempsig[256];
7087 12 memset(tempsig, 0, 256);
7088 12 strcpy(tempsig, DEV_SIGNOFF);
7089
7090
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7091 {
7092 new_return(34);
7093 }
7094
7095 char tempcompilersig[256];
7096 12 memset(tempcompilersig, 0, 256);
7097 12 strcpy(tempcompilersig, COMPILER_NAME);
7098
7099
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7100 {
7101 new_return(35);
7102 }
7103
7104 char tempcompilerversion[256];
7105 12 memset(tempcompilerversion, 0, 256);
7106 #ifdef _MSC_VER
7107 zc_itoa(_MSC_VER,tempcompilerversion,10);
7108 #else
7109 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7110 #endif
7111
7112
7113
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7114 {
7115 new_return(36);
7116 }
7117
7118
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7119 {
7120 new_return(37);
7121 }
7122
7123
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7124 {
7125 new_return(38);
7126 }
7127 #ifdef _MSC_VER
7128 if(!p_iputl((_MSC_VER / 100),f))
7129 {
7130 new_return(39);
7131 }
7132 #else
7133
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7134 {
7135 new_return(39);
7136 }
7137 #endif
7138
7139
7140
7141 #ifdef _MSC_VER
7142 if(!p_iputl((_MSC_VER % 100),f))
7143 {
7144 new_return(41);
7145 }
7146 #else
7147
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7148 {
7149 new_return(41);
7150 }
7151 #endif
7152
7153 #ifdef _MSC_VER
7154 # if _MSC_VER >= 1400
7155 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7156 {
7157 new_return(40);
7158 }
7159 # else
7160 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7161 {
7162 new_return(40);
7163 }
7164 #endif
7165 #else
7166
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7167 {
7168 new_return(40);
7169 }
7170 #endif
7171
7172 #ifdef _MSC_VER
7173 if(!p_iputl((_MSC_BUILD),f))
7174 {
7175 new_return(42);
7176 }
7177 #else
7178
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7179 {
7180 new_return(42);
7181 }
7182 #endif
7183
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7184 {
7185 new_return(43);
7186 }
7187
7188 char tempmodulename[1024];
7189 12 memset(tempmodulename, 0, 1024);
7190 12 strcpy(tempmodulename, moduledata.module_name);
7191
7192
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7193 {
7194 new_return(44);
7195 }
7196
7197 char tempdate[256];
7198 12 memset(tempdate, 0, 256);
7199 12 strcpy(tempdate, __DATE__);
7200
7201
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7202 {
7203 new_return(45);
7204 }
7205 char temptime[256];
7206 12 memset(temptime, 0, 256);
7207 12 strcpy(temptime, __TIME__);
7208
7209
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7210 {
7211 new_return(46);
7212 }
7213
7214
7215 char temptimezone[6];
7216 12 memset(temptimezone, 0, 6);
7217 12 strcpy(temptimezone, __TIMEZONE__);
7218
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7219 {
7220 new_return(47);
7221 }
7222
7223
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7224 {
7225 new_return(48);
7226 }
7227
7228
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7229 {
7230 new_return(49);
7231 }
7232
7233
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7234 {
7235 new_return(50);
7236 }
7237
7238
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7239 {
7240 6 section_size=writesize;
7241 6 }
7242 12 }
7243
7244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7245 {
7246 char ebuf[80];
7247 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7248 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7249 }
7250
7251 6 new_return(0);
7252 }
7253
7254 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7255 {
7256 //these are here to bypass compiler warnings about unused arguments
7257 6 Header=Header;
7258
7259 6 dword section_id=ID_RULES;
7260 6 dword section_version=V_RULES;
7261 6 dword section_cversion=CV_RULES;
7262 6 dword section_size=0;
7263
7264 //section id
7265
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7266 {
7267 new_return(1);
7268 }
7269
7270 //section version info
7271
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7272 {
7273 new_return(2);
7274 }
7275
7276
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7277 {
7278 new_return(3);
7279 }
7280
7281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7282 {
7283 new_return(6);
7284 }
7285
7286
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7287 {
7288 12 fake_pack_writing=(writecycle==0);
7289
7290 //section size
7291
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7292 {
7293 new_return(4);
7294 }
7295
7296 12 writesize=0;
7297
7298 //finally... section data
7299
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7300 {
7301 new_return(5);
7302 }
7303
7304
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7305 {
7306 6 section_size=writesize;
7307 6 }
7308 12 }
7309
7310
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7311 {
7312 char ebuf[80];
7313 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7314 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7315 }
7316
7317 6 new_return(0);
7318 }
7319
7320
7321 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7322 {
7323 //these are here to bypass compiler warnings about unused arguments
7324 6 Header=Header;
7325
7326 6 dword section_id=ID_DOORS;
7327 6 dword section_version=V_DOORS;
7328 6 dword section_cversion=CV_DOORS;
7329 6 dword section_size=0;
7330
7331 //section id
7332
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7333 {
7334 new_return(1);
7335 }
7336
7337 //section version info
7338
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7339 {
7340 new_return(2);
7341 }
7342
7343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7344 {
7345 new_return(3);
7346 }
7347
7348
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7349 {
7350 12 fake_pack_writing=(writecycle==0);
7351
7352 //section size
7353
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7354 {
7355 new_return(4);
7356 }
7357
7358 12 writesize=0;
7359
7360 //finally... section data
7361
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7362 {
7363 new_return(5);
7364 }
7365
7366
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7367 {
7368 //name
7369
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7370 {
7371 new_return(6);
7372 }
7373
7374 //up door
7375
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7376 {
7377
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7378 {
7379
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7380 {
7381 new_return(7);
7382 }
7383 5904 }
7384 1476 }
7385
7386
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7387 {
7388
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7389 {
7390
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7391 {
7392 new_return(8);
7393 }
7394 5904 }
7395 1476 }
7396
7397 //down door
7398
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7399 {
7400
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7401 {
7402
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7403 {
7404 new_return(9);
7405 }
7406 5904 }
7407 1476 }
7408
7409
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7410 {
7411
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7412 {
7413
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7414 {
7415 new_return(10);
7416 }
7417 5904 }
7418 1476 }
7419
7420
7421 //left door
7422
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7423 {
7424
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7425 {
7426
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7427
7428 {
7429 new_return(11);
7430 }
7431 8856 }
7432 1476 }
7433
7434
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7435 {
7436
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7437 {
7438
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7439 {
7440 new_return(12);
7441 }
7442 8856 }
7443 1476 }
7444
7445 //right door
7446
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7447 {
7448
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7449 {
7450
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7451 {
7452 new_return(13);
7453 }
7454 8856 }
7455 1476 }
7456
7457
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7458 {
7459
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7460 {
7461
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7462 {
7463 new_return(14);
7464 }
7465 8856 }
7466 1476 }
7467
7468
7469 //up bomb rubble
7470
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7471 {
7472
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7473 {
7474 new_return(15);
7475 }
7476 328 }
7477
7478
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7479 {
7480
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7481 {
7482 new_return(16);
7483 }
7484 328 }
7485
7486 //down bomb rubble
7487
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7488 {
7489
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7490 {
7491 new_return(17);
7492 }
7493 328 }
7494
7495
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7496 {
7497
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7498 {
7499 new_return(18);
7500 }
7501 328 }
7502
7503 //left bomb rubble
7504
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7505 {
7506
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7507 {
7508 new_return(19);
7509 }
7510 492 }
7511
7512
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7513 {
7514
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7515 {
7516 new_return(20);
7517 }
7518 492 }
7519
7520 //right bomb rubble
7521
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7522 {
7523
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7524 {
7525 new_return(21);
7526 }
7527 492 }
7528
7529
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7530 {
7531
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7532 {
7533 new_return(22);
7534 }
7535 492 }
7536
7537 //walkthrough stuff
7538
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7539 {
7540
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7541 {
7542 new_return(23);
7543 }
7544 656 }
7545
7546
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7547 {
7548
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7549 {
7550 new_return(24);
7551 }
7552 656 }
7553
7554 //flags
7555
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7556 {
7557
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7558 {
7559 new_return(25);
7560 }
7561 328 }
7562 164 }
7563
7564
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7565 {
7566 6 section_size=writesize;
7567 6 }
7568 12 }
7569
7570
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7571 {
7572 char ebuf[80];
7573 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7574 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7575 }
7576
7577 6 new_return(0);
7578 }
7579
7580 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7581 {
7582 //these are here to bypass compiler warnings about unused arguments
7583 6 version=version;
7584 6 build=build;
7585
7586 6 word dmap_count=count_dmaps();
7587 6 dword section_id=ID_DMAPS;
7588 6 dword section_version=V_DMAPS;
7589 6 dword section_cversion=CV_DMAPS;
7590 6 dword section_size=0;
7591
7592 //section id
7593
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7594 {
7595 new_return(1);
7596 }
7597
7598 //section version info
7599
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7600 {
7601 new_return(2);
7602 }
7603
7604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7605 {
7606 new_return(3);
7607 }
7608
7609
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7610 {
7611 12 fake_pack_writing=(writecycle==0);
7612
7613 //section size
7614
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7615 {
7616 new_return(4);
7617 }
7618
7619 12 writesize=0;
7620
7621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7623
7624 //finally... section data
7625
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7626 {
7627 new_return(5);
7628 }
7629
7630
7631
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7632 {
7633 6144 DMaps[i].validate_subscreens();
7634
7635
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7636 {
7637 new_return(6);
7638 }
7639
7640
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7641 {
7642 new_return(7);
7643 }
7644
7645
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7646 {
7647 new_return(8);
7648 }
7649
7650
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7651 {
7652 new_return(9);
7653 }
7654
7655
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7656 {
7657 new_return(10);
7658 }
7659
7660
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7661 {
7662 new_return(11);
7663 }
7664
7665
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7666 {
7667 new_return(12);
7668 }
7669
7670
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7671 {
7672 new_return(13);
7673 }
7674
7675
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7676 {
7677
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7678 {
7679 new_return(14);
7680 }
7681 49152 }
7682
7683
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7684 {
7685 new_return(15);
7686 }
7687
7688
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7689 {
7690 new_return(16);
7691 }
7692
7693
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7694 {
7695 new_return(17);
7696 }
7697
7698
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7699 {
7700 new_return(18);
7701 }
7702
7703
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7704 {
7705 new_return(19);
7706 }
7707
7708
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7709 {
7710 new_return(20);
7711 }
7712
7713
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7714 {
7715 new_return(21);
7716 }
7717
7718
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7719 {
7720 new_return(22);
7721 }
7722
7723
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7724 {
7725 new_return(23);
7726 }
7727
7728
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7729 {
7730 new_return(24);
7731 }
7732
7733
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7734 {
7735 new_return(25);
7736 }
7737
7738
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7739 {
7740 new_return(26);
7741 }
7742
7743
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7744 {
7745 new_return(25);
7746 }
7747
7748
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7749 {
7750 new_return(26);
7751 }
7752
7753
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7754 {
7755 new_return(27);
7756 }
7757
7758 byte disabled[32];
7759 6144 memset(disabled,0,32);
7760
7761
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7762 {
7763
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7764 {
7765 disabled[j/8] |= (1 << (j%8));
7766 }
7767 1572864 }
7768
7769
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7770 {
7771 new_return(28);
7772 }
7773
7774
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7775 {
7776 new_return(29);
7777 }
7778
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7779 {
7780 new_return(30);
7781 }
7782
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7783 {
7784 new_return(31);
7785 }
7786
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7787 {
7788
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7789 {
7790 new_return(32);
7791 }
7792
7793 49152 }
7794
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7795 {
7796
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7797 {
7798
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7799 {
7800 new_return(33);
7801 }
7802 3194880 }
7803 49152 }
7804
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7805 {
7806 new_return(34);
7807 }
7808
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7809 {
7810 new_return(35);
7811 }
7812
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7813 {
7814
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7815 {
7816 new_return(36);
7817 }
7818 49152 }
7819
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7820 {
7821
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7822 {
7823
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7824 {
7825 new_return(37);
7826 }
7827 3194880 }
7828 49152 }
7829
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7830 {
7831 new_return(38);
7832 }
7833
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7834 {
7835
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7836 {
7837 new_return(39);
7838 }
7839 49152 }
7840
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7841 {
7842
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7843 {
7844
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7845 {
7846 new_return(40);
7847 }
7848 3194880 }
7849 49152 }
7850
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7851 {
7852 new_return(41);
7853 }
7854
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7855 {
7856 new_return(42);
7857 }
7858
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7859 {
7860 new_return(43);
7861 }
7862
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7863 {
7864 new_return(44);
7865 }
7866
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7867 {
7868 new_return(45);
7869 }
7870
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7871 new_return(46);
7872
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7873 new_return(47);
7874
7875 // Reserved for z3.
7876
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7877 {
7878
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7879 {
7880
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7881 {
7882 new_return(48);
7883 }
7884 393216 }
7885 49152 }
7886 6144 }
7887
7888
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7889 {
7890 6 section_size=writesize;
7891 6 }
7892 12 }
7893
7894
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7895 {
7896 char ebuf[80];
7897 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7898 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7899 }
7900
7901 6 new_return(0);
7902 }
7903
7904 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7905 {
7906 //these are here to bypass compiler warnings about unused arguments
7907 6 Header=Header;
7908
7909 6 dword section_id=ID_COLORS;
7910 6 dword section_version=V_COLORS;
7911 6 dword section_cversion=CV_COLORS;
7912 6 dword section_size = 0;
7913
7914 //section id
7915
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7916 {
7917 new_return(1);
7918 }
7919
7920
7921 //section version info
7922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7923 {
7924 new_return(2);
7925 }
7926
7927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7928 {
7929 new_return(3);
7930 }
7931
7932
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7933 {
7934 12 fake_pack_writing=(writecycle==0);
7935
7936 //section size
7937
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7938 {
7939 new_return(4);
7940 }
7941
7942 12 writesize=0;
7943
7944
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7945 {
7946 new_return(5);
7947 }
7948
7949
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7950 {
7951 new_return(6);
7952 }
7953
7954
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7955 {
7956 new_return(7);
7957 }
7958
7959
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7960 {
7961 new_return(8);
7962 }
7963
7964
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7965 {
7966 new_return(9);
7967 }
7968
7969
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7970 {
7971 new_return(10);
7972 }
7973
7974
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7975 {
7976 new_return(11);
7977 }
7978
7979
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7980 {
7981 new_return(12);
7982 }
7983
7984
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7985 {
7986 new_return(13);
7987 }
7988
7989
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7990 {
7991 new_return(14);
7992 }
7993
7994
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7995 {
7996 new_return(15);
7997 }
7998
7999
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
8000 {
8001 new_return(16);
8002 }
8003
8004
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
8005 {
8006 new_return(17);
8007 }
8008
8009
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
8010 {
8011 new_return(18);
8012 }
8013
8014
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
8015 {
8016 new_return(19);
8017 }
8018
8019
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
8020 {
8021 new_return(20);
8022 }
8023
8024
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
8025 {
8026 new_return(21);
8027 }
8028
8029
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
8030 {
8031 new_return(22);
8032 }
8033
8034
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
8035 {
8036 new_return(23);
8037 }
8038
8039
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8040 {
8041 new_return(24);
8042 }
8043
8044
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8045 {
8046 new_return(31);
8047 }
8048
8049
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8050 {
8051 new_return(32);
8052 }
8053
8054
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8055 {
8056 new_return(33);
8057 }
8058
8059
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8060 {
8061 new_return(34);
8062 }
8063
8064
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8065 {
8066 new_return(35);
8067 }
8068
8069
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8070 {
8071 new_return(36);
8072 }
8073
8074
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8075 {
8076 new_return(37);
8077 }
8078
8079
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8080 {
8081 new_return(38);
8082 }
8083
8084
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8085 {
8086 new_return(39);
8087 }
8088
8089
8090
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8091 {
8092 6 section_size=writesize;
8093 6 }
8094 12 }
8095
8096
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8097 {
8098 char ebuf[80];
8099 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8100 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8101 }
8102
8103 6 new_return(0);
8104 }
8105
8106 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8107 {
8108 //these are here to bypass compiler warnings about unused arguments
8109 6 Header=Header;
8110
8111 6 dword section_id=ID_ICONS;
8112 6 dword section_version=V_ICONS;
8113 6 dword section_cversion=CV_ICONS;
8114 6 dword section_size = 0;
8115
8116 //section id
8117
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8118 {
8119 new_return(1);
8120 }
8121
8122 //section version info
8123
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8124 {
8125 new_return(2);
8126 }
8127
8128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8129 {
8130 new_return(3);
8131 }
8132
8133
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8134 {
8135 12 fake_pack_writing=(writecycle==0);
8136
8137 //section size
8138
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8139 {
8140 new_return(4);
8141 }
8142
8143 12 writesize=0;
8144
8145
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8146 {
8147
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8148 {
8149 new_return(5);
8150 }
8151 48 }
8152
8153
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8154 {
8155 6 section_size=writesize;
8156 6 }
8157 12 }
8158
8159
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8160 {
8161 char ebuf[80];
8162 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8163 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8164 }
8165
8166 6 new_return(0);
8167 }
8168
8169 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8170 {
8171 //these are here to bypass compiler warnings about unused arguments
8172 6 Header=Header;
8173
8174 6 dword section_id=ID_MISC;
8175 6 dword section_version=V_MISC;
8176 6 dword section_cversion=CV_MISC;
8177 6 word shops=count_shops(&QMisc);
8178 6 word infos=count_infos(&QMisc);
8179 6 word warprings=count_warprings(&QMisc);
8180 6 word triforces=8;
8181 6 dword section_size = 0;
8182
8183 //section id
8184
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8185 {
8186 new_return(1);
8187 }
8188
8189
8190 //section version info
8191
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8192 {
8193 new_return(2);
8194 }
8195
8196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8197 {
8198 new_return(3);
8199 }
8200
8201
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8202 {
8203 12 fake_pack_writing=(writecycle==0);
8204
8205 //section size
8206
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8207 {
8208 new_return(4);
8209 }
8210
8211 12 writesize=0;
8212
8213 //shops
8214
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8215 {
8216 new_return(5);
8217 }
8218
8219
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8220 {
8221
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8222 {
8223 new_return(6);
8224 }
8225
8226
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8227 {
8228
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8229 {
8230 new_return(7);
8231 }
8232 384 }
8233
8234
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8235 {
8236
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8237 {
8238 new_return(8);
8239 }
8240 384 }
8241
8242
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8243 {
8244
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8245 {
8246 new_return(9);
8247 }
8248 384 }
8249 128 }
8250
8251 //infos
8252
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8253 {
8254 new_return(10);
8255 }
8256
8257
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8258 {
8259
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8260 {
8261 new_return(11);
8262 }
8263
8264
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8265 {
8266
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8267 {
8268 new_return(12);
8269 }
8270 384 }
8271
8272
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8273 {
8274
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8275 {
8276 new_return(13);
8277 }
8278 384 }
8279 128 }
8280
8281 //warp rings
8282
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8283 {
8284 new_return(14);
8285 }
8286
8287
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8288 {
8289
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8290 {
8291
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8292 {
8293 new_return(15);
8294 }
8295 1296 }
8296
8297
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8298 {
8299
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8300 {
8301 new_return(16);
8302 }
8303 1296 }
8304
8305
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8306 {
8307 new_return(17);
8308 }
8309 144 }
8310
8311 //triforce pieces
8312
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8313 {
8314
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8315 {
8316 new_return(18);
8317 }
8318 96 }
8319
8320 //end string
8321
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8322 {
8323 new_return(19);
8324 }
8325
8326 //V_MISC >= 8
8327
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8328 {
8329
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8330 {
8331
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8332 {
8333 new_return(20);
8334 }
8335 384 }
8336 128 }
8337 //V_MISC >= 9
8338
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8339 {
8340
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8341 new_return(21);
8342 384 }
8343
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8344 {
8345
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8346
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(QMisc.questmisc_strings[q][j],f))
8347 new_return(22);
8348 384 }
8349 //V_MISC >= 11
8350
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8351 new_return(23);
8352
8353 //V_MISC >= 12
8354
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8355 {
8356
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8357 new_return(24);
8358 3072 }
8359
8360 //V_MISC >= 13
8361
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8362 {
8363 768 bottletype* bt = &(QMisc.bottle_types[q]);
8364
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8365 new_return(25);
8366
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8367 {
8368
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8369 new_return(25);
8370
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8371 new_return(25);
8372 2304 }
8373
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8374 new_return(25);
8375
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8376 new_return(25);
8377 768 }
8378
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8379 {
8380 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8381
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8382 new_return(26);
8383
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8384 {
8385
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8386 new_return(26);
8387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8388 new_return(26);
8389
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8390 new_return(26);
8391
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8392 new_return(26);
8393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8394 new_return(26);
8395 9216 }
8396 3072 }
8397
8398 //V_MISC >= 14
8399
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8400 {
8401
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8402 new_return(27);
8403 3072 }
8404
8405
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8406 {
8407 6 section_size=writesize;
8408 6 }
8409 12 }
8410
8411
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8412 {
8413 char ebuf[80];
8414 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8415 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8416 }
8417
8418 6 new_return(0);
8419 }
8420
8421 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8422 {
8423 //these are here to bypass compiler warnings about unused arguments
8424 6 Header=Header;
8425
8426 6 dword section_id=ID_ITEMS;
8427 6 dword section_version=V_ITEMS;
8428 6 dword section_cversion=CV_ITEMS;
8429 // dword section_size=0;
8430 6 dword section_size = 0;
8431
8432 //section id
8433
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8434 {
8435 new_return(1);
8436 }
8437
8438 //section version info
8439
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8440 {
8441 new_return(2);
8442 }
8443
8444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8445 {
8446 new_return(3);
8447 }
8448
8449
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8450 {
8451 12 fake_pack_writing=(writecycle==0);
8452
8453 //section size
8454
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8455 {
8456 new_return(4);
8457 }
8458
8459 12 writesize=0;
8460
8461 //finally... section data
8462
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8463 {
8464 new_return(5);
8465 }
8466
8467
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8468 {
8469
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8470 {
8471 new_return(5);
8472 }
8473 3072 }
8474
8475
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8476 {
8477
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8478 {
8479 new_return(6);
8480 }
8481
8482
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8483 {
8484 new_return(7);
8485 }
8486
8487
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8488 {
8489 new_return(8);
8490 }
8491
8492
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8493 {
8494 new_return(9);
8495 }
8496
8497
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8498 {
8499 new_return(10);
8500 }
8501
8502
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8503 {
8504 new_return(11);
8505 }
8506
8507
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8508 {
8509 new_return(12);
8510 }
8511
8512
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8513 {
8514 new_return(13);
8515 }
8516
8517
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8518 {
8519 new_return(14);
8520 }
8521
8522
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8523 {
8524 new_return(14);
8525 }
8526
8527
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8528 {
8529 new_return(15);
8530 }
8531
8532
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8533 {
8534 new_return(16);
8535 }
8536
8537
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8538 {
8539 new_return(17);
8540 }
8541
8542
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8543 {
8544 new_return(18);
8545 }
8546
8547
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8548 {
8549 new_return(19);
8550 }
8551
8552
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8553 {
8554 new_return(21);
8555 }
8556
8557
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8558 {
8559 new_return(22);
8560 }
8561
8562
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8563 {
8564 new_return(23);
8565 }
8566
8567
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8568 {
8569
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8570 {
8571 new_return(24);
8572 }
8573 24576 }
8574
8575
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8576 {
8577
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8578 {
8579 new_return(25);
8580 }
8581 6144 }
8582
8583
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8584 {
8585 new_return(26);
8586 }
8587
8588
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8589 {
8590 new_return(27);
8591 }
8592
8593
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8594 {
8595 new_return(28);
8596 }
8597
8598
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8599 {
8600 new_return(29);
8601 }
8602
8603
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8604 {
8605 new_return(30);
8606 }
8607
8608
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8609 {
8610 new_return(31);
8611 }
8612
8613
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8614 {
8615 new_return(32);
8616 }
8617
8618
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8619 {
8620 new_return(33);
8621 }
8622
8623
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8624 {
8625 new_return(34);
8626 }
8627
8628
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8629 {
8630 new_return(35);
8631 }
8632
8633
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8634 {
8635 new_return(36);
8636 }
8637
8638
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8639 {
8640 new_return(37);
8641 }
8642
8643
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8644 {
8645 new_return(38);
8646 }
8647
8648
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8649 {
8650
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8651 {
8652 new_return(39);
8653 }
8654 6144 }
8655
8656
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8657 {
8658 new_return(40);
8659 }
8660
8661
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8662 {
8663 new_return(41);
8664 }
8665
8666
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8667 {
8668 new_return(42);
8669 }
8670
8671
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8672 {
8673 new_return(43);
8674 }
8675
8676
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8677 {
8678 new_return(44);
8679 }
8680
8681
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8682 {
8683 new_return(45);
8684 }
8685
8686
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8687 {
8688 new_return(46);
8689 }
8690
8691
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8692 {
8693 new_return(47);
8694 }
8695
8696
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8697 {
8698 new_return(48);
8699 }
8700
8701
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8702 {
8703 new_return(48);
8704 }
8705
8706 //New itemdata vars -Z
8707 //! version 27
8708
8709
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8710 {
8711 new_return(49);
8712 }
8713
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8714 {
8715 new_return(50);
8716 }
8717
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8718 {
8719 new_return(51);
8720 }
8721
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8722 {
8723 new_return(52);
8724 }
8725
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8726
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8727 {
8728 new_return(53);
8729 }
8730 30720 }
8731 //version 28
8732
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8733 {
8734 new_return(54);
8735 }
8736
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8737 {
8738
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8739 {
8740 new_return(55);
8741 }
8742 24576 }
8743
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8744 {
8745
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8746 {
8747 new_return(56);
8748 }
8749 6144 }
8750
8751
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8752 {
8753 new_return(57);
8754 }
8755
8756
8757
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8758 {
8759 new_return(58);
8760 }
8761
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8762 {
8763 new_return(59);
8764 }
8765
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8766 {
8767 new_return(60);
8768 }
8769
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8770 {
8771 new_return(61);
8772 }
8773
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8774 {
8775 new_return(62);
8776 }
8777
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8778 {
8779 new_return(63);
8780 }
8781
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8782 {
8783 new_return(64);
8784 }
8785
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8786 {
8787 new_return(65);
8788 }
8789
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8790 {
8791 new_return(66);
8792 }
8793
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8794 {
8795 new_return(67);
8796 }
8797
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8798 {
8799 new_return(68);
8800 }
8801
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8802 {
8803 new_return(69);
8804 }
8805
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8806 {
8807 new_return(70);
8808 }
8809
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8810 {
8811 new_return(71);
8812 }
8813
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8814 {
8815 new_return(72);
8816 }
8817
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8818 {
8819 new_return(73);
8820 }
8821
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8822 {
8823
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8824 {
8825 new_return(74);
8826 }
8827 6144 }
8828
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8829 {
8830 new_return(75);
8831 }
8832
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8833 {
8834 new_return(76);
8835 }
8836
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8837 {
8838 new_return(77);
8839 }
8840
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8841 {
8842 new_return(78);
8843 }
8844
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8845 {
8846 new_return(79);
8847 }
8848
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8849 {
8850 new_return(80);
8851 }
8852
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8853 {
8854 new_return(81);
8855 }
8856
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8857 {
8858 new_return(82);
8859 }
8860
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8861 {
8862 new_return(83);
8863 }
8864
8865
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8866 {
8867
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8868 {
8869 new_return(84);
8870 }
8871 6144 }
8872
8873 //InitD[] labels
8874
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8875 {
8876
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8877 {
8878
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8879 {
8880 new_return(85);
8881 }
8882 1597440 }
8883
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8884 {
8885
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8886 {
8887 new_return(86);
8888 }
8889 1597440 }
8890
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8891 {
8892
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8893 {
8894 new_return(87);
8895 }
8896 1597440 }
8897
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8898 {
8899 new_return(88);
8900 }
8901 24576 }
8902
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8903 {
8904
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8905 {
8906 new_return(89);
8907 }
8908
8909 6144 }
8910
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8911 {
8912 new_return(90);
8913 }
8914
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8915 {
8916 new_return(91);
8917 }
8918
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8919
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8920 new_return(92);
8921
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < BURNSPR_MAX; ++q)
8922 {
8923
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8924 new_return(93);
8925
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8926 new_return(94);
8927 15360 }
8928 3072 }
8929
8930
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8931 {
8932 6 section_size=writesize;
8933 6 }
8934 12 }
8935
8936
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8937 {
8938 char ebuf[80];
8939 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8940 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8941 }
8942
8943 6 new_return(0);
8944 }
8945
8946 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8947 {
8948 //these are here to bypass compiler warnings about unused arguments
8949 6 Header=Header;
8950
8951 6 dword section_id=ID_WEAPONS;
8952 6 dword section_version=V_WEAPONS;
8953 6 dword section_cversion=CV_WEAPONS;
8954 6 dword section_size = 0;
8955
8956 //section id
8957
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8958 {
8959 new_return(1);
8960 }
8961
8962 //section version info
8963
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8964 {
8965 new_return(2);
8966 }
8967
8968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8969 {
8970 new_return(3);
8971 }
8972
8973
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8974 {
8975 12 fake_pack_writing=(writecycle==0);
8976
8977 //section size
8978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8979 {
8980 new_return(4);
8981 }
8982
8983 12 writesize=0;
8984
8985 //finally... section data
8986
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8987 {
8988 new_return(5);
8989 }
8990
8991
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8992 {
8993
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8994 {
8995 new_return(5);
8996 }
8997 3072 }
8998
8999
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
9000 {
9001
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
9002 {
9003 new_return(7);
9004 }
9005
9006
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
9007 {
9008 new_return(8);
9009 }
9010
9011
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
9012 {
9013 new_return(9);
9014 }
9015
9016
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
9017 {
9018 new_return(10);
9019 }
9020
9021
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
9022 {
9023 new_return(11);
9024 }
9025
9026
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
9027 {
9028 new_return(12);
9029 }
9030
9031
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
9032 {
9033 new_return(12);
9034 }
9035 3072 }
9036
9037
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9038 {
9039 6 section_size=writesize;
9040 6 }
9041 12 }
9042
9043
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9044 {
9045 char ebuf[80];
9046 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9047 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9048 }
9049
9050 6 new_return(0);
9051 }
9052
9053 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9054 {
9055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9056 return qe_invalid;
9057
9058 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9059 4080 bool is_0x80_screen = j >= 0x80;
9060
9061
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9062 return qe_invalid;
9063
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9064 1998 return qe_OK;
9065 //Calculate what needs writing
9066 2082 uint32_t scr_has_flags = 0;
9067
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9068
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9069 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9070
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9071 290 scr_has_flags |= SCRHAS_ITEM;
9072
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9073 18 scr_has_flags |= SCRHAS_TWARP;
9074
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9075 {
9076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9077
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9078
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9079 {
9080 168 scr_has_flags |= SCRHAS_TWARP;
9081 168 break;
9082 }
9083 7586 }
9084
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9085
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9086 6 scr_has_flags |= SCRHAS_SWARP;
9087
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9088 {
9089
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9090
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9091
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9092 {
9093 1440 scr_has_flags |= SCRHAS_SWARP;
9094 1440 break;
9095 }
9096 2544 }
9097
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9098 44 scr_has_flags |= SCRHAS_WARPRET;
9099
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9100 {
9101
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9102 {
9103 588 scr_has_flags |= SCRHAS_WARPRET;
9104 588 break;
9105 }
9106 5800 }
9107
9108
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9109 scr_has_flags |= SCRHAS_LAYERS;
9110
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9111 {
9112
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9113
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9114 {
9115 192 scr_has_flags |= SCRHAS_LAYERS;
9116 192 break;
9117 }
9118 11356 }
9119
9120
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9121 4 scr_has_flags |= SCRHAS_MAZE;
9122
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9123 {
9124
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9125 {
9126 scr_has_flags |= SCRHAS_MAZE;
9127 break;
9128 }
9129 8312 }
9130
9131
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9132
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9133
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9134 1330 scr_has_flags |= SCRHAS_D_S_U;
9135
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9136 {
9137
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9138 {
9139 732 scr_has_flags |= SCRHAS_D_S_U;
9140 732 break;
9141 }
9142 80 }
9143
9144
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9145
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9146
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9147
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9148
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9149
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9150 2082 scr_has_flags |= SCRHAS_FLAGS;
9151
9152
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9153 50 scr_has_flags |= SCRHAS_ENEMY;
9154
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9155 {
9156
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9157 {
9158 640 scr_has_flags |= SCRHAS_ENEMY;
9159 640 break;
9160 }
9161 13920 }
9162
9163
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9164
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9165 6 scr_has_flags |= SCRHAS_CARRY;
9166
9167
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9168 18 scr_has_flags |= SCRHAS_SCRIPT;
9169
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9170 {
9171
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9172 {
9173 scr_has_flags |= SCRHAS_SCRIPT;
9174 break;
9175 }
9176 16512 }
9177
9178
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9179 {
9180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9181
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9182
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9183
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9184 {
9185 scr_has_flags |= SCRHAS_UNUSED;
9186 break;
9187 }
9188 20820 }
9189
9190
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9191 {
9192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9193
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9194
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9195 {
9196 1324 scr_has_flags |= SCRHAS_SECRETS;
9197 1324 break;
9198 }
9199 98028 }
9200
9201
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9202 {
9203
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9204
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9205 {
9206 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9207 1910 break;
9208 }
9209 38318 }
9210
9211
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9212
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9213
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9214 || screen.timedwarptics || screen.screen_midi != -1
9215 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9216 2082 scr_has_flags |= SCRHAS_MISC;
9217
9218
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9219 return qe_invalid;
9220
9221 //Write stuff
9222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9223 {
9224
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9233 return qe_invalid;
9234
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9235 return qe_invalid;
9236
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9237 return qe_invalid;
9238 2082 }
9239
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9240 {
9241
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9244 return qe_invalid;
9245
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9246 return qe_invalid;
9247
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9248 return qe_invalid;
9249 290 }
9250
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9251 {
9252
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9253 return qe_invalid;
9254 1500 }
9255
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9256 {
9257
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9258 {
9259
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9260 return qe_invalid;
9261 744 }
9262
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9263 {
9264
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9265 return qe_invalid;
9266 744 }
9267
9268
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9269 {
9270
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9271 return qe_invalid;
9272 744 }
9273
9274
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9275 return qe_invalid;
9276 186 }
9277
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9278 {
9279
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9280 {
9281
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9282 return qe_invalid;
9283 5784 }
9284
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9285 {
9286
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9287 return qe_invalid;
9288 5784 }
9289
9290
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9291 {
9292
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9293 return qe_invalid;
9294 5784 }
9295
9296
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9299 return qe_invalid;
9300 1446 }
9301
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9302 {
9303
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9304 {
9305
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9306 return qe_invalid;
9307 2528 }
9308
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9309 {
9310
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9311 return qe_invalid;
9312 2528 }
9313
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9314 return qe_invalid;
9315
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9316 return qe_invalid;
9317 632 }
9318
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9319 {
9320
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9321 {
9322
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9323 return qe_invalid;
9324 1152 }
9325
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9326 {
9327
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9328 return qe_invalid;
9329 1152 }
9330
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9331 {
9332
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9333 return qe_invalid;
9334 1152 }
9335
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9336 return qe_invalid;
9337
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9338 return qe_invalid;
9339 192 }
9340
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9341 {
9342
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9343 {
9344
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9345 return qe_invalid;
9346 16 }
9347
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9348 return qe_invalid;
9349 4 }
9350
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9351 {
9352
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9353 return qe_invalid;
9354
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9355 {
9356
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9357 return qe_invalid;
9358 8248 }
9359
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9360 return qe_invalid;
9361
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9362 return qe_invalid;
9363
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9364 return qe_invalid;
9365
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9366 return qe_invalid;
9367 2062 }
9368
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9369 {
9370
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9371 return qe_invalid;
9372
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9373 return qe_invalid;
9374
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9375 return qe_invalid;
9376
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9377 return qe_invalid;
9378
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9379 return qe_invalid;
9380
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9381 return qe_invalid;
9382
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9383 return qe_invalid;
9384
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9385 return qe_invalid;
9386
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9387 return qe_invalid;
9388
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9389 return qe_invalid;
9390
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9391 return qe_invalid;
9392 746 }
9393
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9394 {
9395
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9396 {
9397
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9398 return qe_invalid;
9399 6900 }
9400
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9401 return qe_invalid;
9402 690 }
9403
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9404 {
9405
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9406 return qe_invalid;
9407
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9408 return qe_invalid;
9409
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9410 return qe_invalid;
9411
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9412 return qe_invalid;
9413 6 }
9414
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9415 {
9416
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9417 return qe_invalid;
9418
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9419 return qe_invalid;
9420
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9421 {
9422
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9423 return qe_invalid;
9424 144 }
9425 18 }
9426
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9427 {
9428 for ( int32_t q = 0; q < 10; q++ )
9429 {
9430 if(!p_iputl(screen.npcstrings[q],f))
9431 return qe_invalid;
9432 }
9433 for ( int32_t q = 0; q < 10; q++ )
9434 {
9435 if(!p_iputw(screen.new_items[q],f))
9436 return qe_invalid;
9437 }
9438 for ( int32_t q = 0; q < 10; q++ )
9439 {
9440 if(!p_iputw(screen.new_item_x[q],f))
9441 return qe_invalid;
9442 }
9443 for ( int32_t q = 0; q < 10; q++ )
9444 {
9445 if(!p_iputw(screen.new_item_y[q],f))
9446 return qe_invalid;
9447 }
9448 }
9449
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9450 {
9451
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9452 {
9453
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9454 return qe_invalid;
9455 169472 }
9456
9457
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9458 {
9459
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9460 return qe_invalid;
9461 169472 }
9462
9463
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9464 {
9465
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9466 return qe_invalid;
9467 169472 }
9468 1324 }
9469
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9470 {
9471
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9472 {
9473
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9474 return qe_invalid;
9475 336160 }
9476
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9477 {
9478
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9479 return qe_invalid;
9480 336160 }
9481
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9482 {
9483
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9484 return qe_invalid;
9485 336160 }
9486 1910 }
9487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9488 {
9489
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9490 return qe_invalid;
9491
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9492 return qe_invalid;
9493
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9494 return qe_invalid;
9495
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9496 return qe_invalid;
9497
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9498 return qe_invalid;
9499
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9500 return qe_invalid;
9501
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9502 return qe_invalid;
9503
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9504 return qe_invalid;
9505
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9506 return qe_invalid;
9507
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9508 return qe_invalid;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9510 return qe_invalid;
9511 2082 }
9512
9513 2082 dword numffc = screen.numFFC();
9514
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9515 return qe_invalid;
9516
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9517 {
9518 45816 ffcdata const& tempffc = screen.ffcs[k];
9519
9520
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9521 return qe_invalid;
9522
9523
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9524 44726 continue;
9525
9526
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9527 return qe_invalid;
9528
9529
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9530 return qe_invalid;
9531
9532
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9533 return qe_invalid;
9534
9535
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9536 return qe_invalid;
9537
9538
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9539 return qe_invalid;
9540
9541
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9542 return qe_invalid;
9543
9544
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9545 return qe_invalid;
9546
9547
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9548 return qe_invalid;
9549
9550
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9551 return qe_invalid;
9552
9553
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9554 return qe_invalid;
9555
9556
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9557 return qe_invalid;
9558
9559
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9560 return qe_invalid;
9561
9562
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9563 return qe_invalid;
9564
9565
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9566 return qe_invalid;
9567
9568
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9569 return qe_invalid;
9570
9571
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9572 {
9573
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9574 return qe_invalid;
9575 8720 }
9576
9577
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9578 return qe_invalid;
9579
9580
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9581 return qe_invalid;
9582 1090 }
9583
9584
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9585 return qe_invalid;
9586
9587 2082 return qe_OK;
9588 4080 }
9589
9590 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9591 {
9592 6 dword section_id=ID_MAPS;
9593 6 dword section_version=V_MAPS;
9594 6 dword section_cversion=CV_MAPS;
9595 6 dword section_size = 0;
9596
9597 //section id
9598
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9599 {
9600 new_return(1);
9601 }
9602
9603 //section version info
9604
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9605 {
9606 new_return(2);
9607 }
9608
9609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9610 {
9611 new_return(3);
9612 }
9613
9614
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9615 {
9616 12 fake_pack_writing=(writecycle==0);
9617
9618 //section size
9619
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9620 {
9621 new_return(4);
9622 }
9623
9624 12 writesize=0;
9625
9626
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9627 {
9628 new_return(5);
9629 }
9630 12 map_autolayers.resize(map_count*6);
9631
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9632 {
9633 30 byte valid = 0;
9634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9635 {
9636
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9637 break;
9638 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9639
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9640 {
9641 30 valid = 1;
9642 30 break;
9643 }
9644 210 }
9645
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9646 {
9647 new_return(6);
9648 }
9649
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9650
9651 { //per-map info
9652
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9653 {
9654 180 size_t ind = i*6+q;
9655
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9656 new_return(7);
9657 180 }
9658 }
9659
9660
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9661 4080 writemapscreen(f,i,j);
9662 30 }
9663
9664
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9665 {
9666 6 section_size=writesize;
9667 6 }
9668 12 }
9669
9670
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9671 {
9672 char ebuf[80];
9673 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9674 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9675 }
9676
9677 6 new_return(0);
9678 }
9679
9680 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9681 {
9682 //Check what needs writing
9683 byte combo_has_flags = 0;
9684 383638 for(auto q = 0; q < 8; ++q)
9685 {
9686 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9687 383638 || (q < 4 && tmp_cmb.attributes[q]))
9688 {
9689 combo_has_flags |= CHAS_ATTRIB;
9690 break;
9691 }
9692 383638 }
9693
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9694
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9695
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9696
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9697
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9698
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9699
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9700
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9701
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9702
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9703
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9704
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9705
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9706
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9707
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9708
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9709
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9710
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9711
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9712
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9713
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9714
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9715
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9716
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9717 96892 combo_has_flags |= CHAS_TRIG;
9718
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9719
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9720 combo_has_flags |= CHAS_TRIG;
9721
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9722 193592 combo_has_flags |= CHAS_FLAG;
9723
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9724
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9725
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9726 196334 combo_has_flags |= CHAS_ANIM;
9727
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9728 70224 combo_has_flags |= CHAS_SCRIPT;
9729
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9730 {
9731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9732 {
9733 combo_has_flags |= CHAS_SCRIPT;
9734 break;
9735 }
9736 776032 }
9737
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9738
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9739 185268 combo_has_flags |= CHAS_BASIC;
9740
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9741
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9742
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9743
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9744
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9745
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9746
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9747 131132 combo_has_flags |= CHAS_LIFT;
9748
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9749
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9750
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9751 131132 combo_has_flags |= CHAS_GENERAL;
9752
9753
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9754 {
9755 34128 return 50;
9756 }
9757
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9758 //Write the combo
9759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9760 {
9761
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9762 return 6;
9763
9764
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9765 return 7;
9766
9767
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9768 return 8;
9769
9770
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9771 return 9;
9772
9773
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9774 return 15;
9775
9776
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9777 return 10;
9778 44820 }
9779
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9780 {
9781 p_putcstr(tmp_cmb.label, f);
9782
9783 if(!p_iputw(tmp_cmb.script,f))
9784 return 26;
9785 for ( int32_t q = 0; q < 8; q++ )
9786 if(!p_iputl(tmp_cmb.initd[q],f))
9787 return 27;
9788 }
9789
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9790 {
9791
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9792 return 11;
9793
9794
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9795 return 12;
9796
9797
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9798 return 13;
9799
9800
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9801 return 14;
9802
9803
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9804 return 16;
9805
9806
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9807 return 18;
9808
9809
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9810 return 19;
9811 17346 }
9812
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9813 {
9814
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9816 return 20;
9817
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9819 return 25;
9820
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9822 return 32;
9823 2268 }
9824
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9825 {
9826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9827 return 21;
9828
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9829 return 33;
9830 184 }
9831
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9832 {
9833
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9835 return 22;
9836
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9837 return 23;
9838
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9839 return 34;
9840
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9841 return 35;
9842
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9843 return 36;
9844
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9845 return 37;
9846
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9847 return 38;
9848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9849 return 39;
9850
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9851 return 40;
9852
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9853 return 41;
9854
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9855 return 42;
9856
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9857 return 43;
9858
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9859 return 44;
9860
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9861 return 45;
9862
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9863 return 46;
9864
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9865 return 47;
9866
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9867 return 48;
9868
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9869 return 49;
9870
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9871 return 50;
9872
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9873 return 51;
9874
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9875 return 52;
9876
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9877 return 53;
9878
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9879 return 69;
9880
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9881 return 70;
9882
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9883 return 71;
9884
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9885 return 72;
9886
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9887 return 76;
9888
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9889 return 77;
9890
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9891 return 89;
9892
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9893 return 90;
9894
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9895 return 91;
9896
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9897 return 92;
9898
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9899
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9900 return 93;
9901
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9902 return 94;
9903
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9904 return 95;
9905
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9906 return 96;
9907
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9908 return 97;
9909
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9910 return 98;
9911
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9912 return 99;
9913
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9914 return 100;
9915
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9916 return 101;
9917
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9918 return 102;
9919
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9920 return 103;
9921 168 }
9922
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9923 {
9924
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9925 return 54;
9926
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9927 return 55;
9928
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9929 return 56;
9930
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9931 return 57;
9932
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9933 return 58;
9934
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9935 return 59;
9936
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9937 return 60;
9938
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9939 return 61;
9940
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9941 return 62;
9942
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9943 return 63;
9944
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9945 return 64;
9946
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9947 return 65;
9948
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9949 return 66;
9950
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9951 return 67;
9952
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9953 return 68;
9954
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9955 return 78;
9956 8 }
9957
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9958 {
9959
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9960 return 73;
9961
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9962 return 74;
9963
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9964 return 75;
9965
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9966 return 79;
9967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9968 return 80;
9969
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9970 return 81;
9971
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9972 return 82;
9973
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9974 return 83;
9975
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9976 return 84;
9977
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9978 return 85;
9979
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9980 return 86;
9981
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9982 return 87;
9983
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9984 return 88;
9985 8 }
9986 44820 return 0;
9987 131132 }
9988
9989 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9990 {
9991 //these are here to bypass compiler warnings about unused arguments
9992 6 version=version;
9993 6 build=build;
9994
9995 word combos_used;
9996 6 dword section_id=ID_COMBOS;
9997 6 dword section_version=V_COMBOS;
9998 6 dword section_cversion=CV_COMBOS;
9999 // dword section_size=0;
10000 6 combos_used = count_combos()-start_combo;
10001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
10002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
10003 6 dword section_size = 0;
10004
10005 //section id
10006
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10007 {
10008 new_return(1);
10009 }
10010
10011 //section version info
10012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10013 {
10014 new_return(2);
10015 }
10016
10017
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10018 {
10019 new_return(3);
10020 }
10021
10022
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10023 {
10024 12 fake_pack_writing=(writecycle==0);
10025
10026 //section size
10027
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10028 {
10029 new_return(4);
10030 }
10031
10032 12 writesize=0;
10033
10034 //finally... section data
10035 12 combos_used=count_combos()-start_combo;
10036
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
10037
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
10038
10039
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10040 {
10041 new_return(5);
10042 }
10043
10044 12 size_t end_combo = start_combo+combos_used;
10045
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10046 {
10047 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10048
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10049 97004 }
10050
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10051 {
10052 6 section_size=writesize;
10053 6 }
10054 12 }
10055
10056
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10057 {
10058 char ebuf[80];
10059 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10060 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10061 }
10062
10063 6 new_return(0);
10064 6 }
10065
10066 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10067 {
10068 //these are here to bypass compiler warnings about unused arguments
10069 6 version=version;
10070 6 build=build;
10071
10072 6 dword section_id=ID_COMBOALIASES;
10073 6 dword section_version=V_COMBOALIASES;
10074 6 dword section_cversion=CV_COMBOALIASES;
10075 6 dword section_size=0;
10076
10077 //section id
10078
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10079 {
10080 new_return(1);
10081 }
10082
10083 //section version info
10084
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10085 {
10086 new_return(2);
10087 }
10088
10089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10090 {
10091 new_return(3);
10092 }
10093
10094
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10095 {
10096 12 fake_pack_writing=(writecycle==0);
10097
10098 //section size
10099
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10100 {
10101 new_return(4);
10102 }
10103
10104 12 writesize=0;
10105
10106 //finally... section data
10107
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10108 {
10109
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10110 {
10111 new_return(5);
10112 }
10113
10114
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10115 {
10116 new_return(6);
10117 }
10118
10119 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10120
10121
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10122 {
10123 new_return(7);
10124 }
10125
10126
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10127 {
10128 new_return(8);
10129 }
10130
10131
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10132 {
10133 new_return(9);
10134 }
10135
10136
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10137 {
10138
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10139 {
10140 new_return(10);
10141 }
10142 99792 }
10143
10144
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10145 {
10146
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10147 {
10148 new_return(11);
10149 }
10150 99792 }
10151 98304 }
10152
10153 //Combo pools!
10154 int16_t num_cpools;
10155
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10156 {
10157
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10158 {
10159 2 ++num_cpools;
10160 2 break;
10161 }
10162 98298 }
10163
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10164
10165
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10166 {
10167 new_return(12);
10168 }
10169
10170
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10171 {
10172 6 combo_pool const& pool = combo_pools[cp];
10173 6 int32_t num_combos = pool.combos.size();
10174
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10175 {
10176 new_return(13);
10177 }
10178
10179
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10180 {
10181 26 cpool_entry const& entry = pool.combos.at(q);
10182
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10183 {
10184 new_return(14);
10185 }
10186
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10187 {
10188 new_return(15);
10189 }
10190
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10191 {
10192 new_return(16);
10193 }
10194 26 }
10195 6 }
10196
10197 //Autocombos!
10198 int16_t num_cautos;
10199
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10200 {
10201
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10202 {
10203 ++num_cautos;
10204 break;
10205 }
10206 98304 }
10207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10208
10209
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10210 {
10211 new_return(17);
10212 }
10213
10214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10215 {
10216 combo_auto const& cauto = combo_autos[ca];
10217 if (!p_putc(cauto.getType(), f))
10218 {
10219 new_return(18);
10220 }
10221 if (!p_iputl(cauto.getIconDisplay(), f))
10222 {
10223 new_return(19);
10224 }
10225 if (!p_iputl(cauto.getEraseCombo(), f))
10226 {
10227 new_return(20);
10228 }
10229 if (!p_putc(cauto.getFlags(), f))
10230 {
10231 new_return(21);
10232 }
10233 if (!p_putc(cauto.getArg(), f))
10234 {
10235 new_return(22);
10236 }
10237 int32_t num_combos = cauto.combos.size();
10238 if (!p_iputl(num_combos, f))
10239 {
10240 new_return(23);
10241 }
10242
10243 for (auto q = 0; q < num_combos; ++q)
10244 {
10245 autocombo_entry const& entry = cauto.combos.at(q);
10246 if (!p_putc(entry.ctype, f))
10247 {
10248 new_return(24);
10249 }
10250 if (!p_iputl(entry.cid, f))
10251 {
10252 new_return(25);
10253 }
10254 }
10255 }
10256
10257
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10258 {
10259 6 section_size=writesize;
10260 6 }
10261 12 }
10262
10263
10264
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10265 {
10266 char ebuf[80];
10267 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10268 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10269 }
10270
10271 6 new_return(0);
10272 }
10273
10274 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10275 {
10276 //these are here to bypass compiler warnings about unused arguments
10277 6 version=version;
10278 6 build=build;
10279 6 start_cset=start_cset;
10280 6 max_csets=max_csets;
10281
10282 6 dword section_id=ID_CSETS;
10283 6 dword section_version=V_CSETS;
10284 6 dword section_cversion=CV_CSETS;
10285 6 int32_t palcycles = count_palcycles(&QMisc);
10286 // int32_t palcyccount = count_palcycles(&QMisc);
10287 6 dword section_size = 0;
10288
10289 //section id
10290
10291
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10292 {
10293 new_return(1);
10294 }
10295
10296 //section version info
10297
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10298 {
10299 new_return(2);
10300 }
10301
10302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10303 {
10304 new_return(3);
10305 }
10306
10307
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10308 {
10309 12 fake_pack_writing=(writecycle==0);
10310
10311 //section size
10312
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10313 {
10314 new_return(4);
10315 }
10316
10317 12 writesize=0;
10318
10319 //finally... section data
10320
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10321 {
10322 new_return(5);
10323 }
10324
10325
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10326 {
10327 new_return(6);
10328 }
10329
10330
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10331 {
10332 new_return(15);
10333 }
10334
10335
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10336 {
10337
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10338 {
10339
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10340 {
10341 new_return(16);
10342 }
10343 828 }
10344
10345
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10346 {
10347
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10348 {
10349 new_return(17);
10350 }
10351 828 }
10352
10353
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10354 {
10355
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10356 {
10357 new_return(18);
10358 }
10359 828 }
10360 276 }
10361
10362
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10363 {
10364 6 section_size=writesize;
10365 6 }
10366 12 }
10367
10368
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10369 {
10370 char ebuf[80];
10371 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10372 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10373 }
10374
10375 6 new_return(0);
10376 }
10377
10378 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10379 {
10380 //these are here to bypass compiler warnings about unused arguments
10381 6 version=version;
10382 6 build=build;
10383 6 start_msgstr=start_msgstr;
10384 6 max_msgstrs=max_msgstrs;
10385
10386 6 dword section_id=ID_STRINGS;
10387 6 dword section_version=V_STRINGS;
10388 6 dword section_cversion=CV_STRINGS;
10389 6 dword section_size = 0;
10390
10391 //section id
10392
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10393 {
10394 new_return(1);
10395 }
10396
10397 //section version info
10398
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10399 {
10400 new_return(2);
10401 }
10402
10403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10404 {
10405 new_return(3);
10406 }
10407
10408
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10409 {
10410 12 fake_pack_writing=(writecycle==0);
10411
10412 //section size
10413
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10414 {
10415 new_return(4);
10416 }
10417
10418 12 writesize=0;
10419
10420 //finally... section data
10421
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10422 {
10423 return qe_invalid;
10424 }
10425
10426
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10427 {
10428 302 int32_t sz = MsgStrings[i].s.size();
10429
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10430
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10431 {
10432 return qe_invalid;
10433 }
10434
10435 302 char const* tmpstr = MsgStrings[i].s.c_str();
10436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10437 {
10438
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10439 {
10440 return qe_invalid;
10441 }
10442 302 }
10443
10444
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10445 {
10446 return qe_invalid;
10447 }
10448
10449
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10450 {
10451 return qe_invalid;
10452 }
10453
10454
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10455 {
10456 return qe_invalid;
10457 }
10458
10459
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10460 {
10461 return qe_invalid;
10462 }
10463
10464
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10465 {
10466 return qe_invalid;
10467 }
10468
10469
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10470 {
10471 return qe_invalid;
10472 }
10473
10474
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10475 {
10476 return qe_invalid;
10477 }
10478
10479
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10480 {
10481 return qe_invalid;
10482 }
10483
10484
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10485 {
10486 return qe_invalid;
10487 }
10488
10489
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10490 {
10491 return qe_invalid;
10492 }
10493
10494
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10495 {
10496 return qe_invalid;
10497 }
10498
10499
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10500 {
10501 return qe_invalid;
10502 }
10503
10504
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10505 {
10506
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10507 {
10508 return qe_invalid;
10509 }
10510 1208 }
10511
10512
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10513 {
10514 return qe_invalid;
10515 }
10516
10517
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10518 {
10519 return qe_invalid;
10520 }
10521
10522
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10523 {
10524 return qe_invalid;
10525 }
10526
10527
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10528 {
10529 return qe_invalid;
10530 }
10531
10532
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10533 {
10534 return qe_invalid;
10535 }
10536
10537
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10538 {
10539 return qe_invalid;
10540 }
10541
10542
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10543 {
10544 return qe_invalid;
10545 }
10546
10547
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10548 {
10549 return qe_invalid;
10550 }
10551
10552
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10553 {
10554 return qe_invalid;
10555 }
10556
10557
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10558 {
10559 return qe_invalid;
10560 }
10561
10562
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10563 {
10564 return qe_invalid;
10565 }
10566 302 }
10567
10568
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10569 {
10570 6 section_size=writesize;
10571 6 }
10572 12 }
10573
10574
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10575 {
10576 char ebuf[80];
10577 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10578 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10579 }
10580
10581 6 new_return(0);
10582 6 }
10583
10584 int32_t writestrings_text(PACKFILE *f)
10585 {
10586 std::map<int32_t, int32_t> msglistcache;
10587
10588 for(int32_t index = 1; index<msg_count; index++)
10589 {
10590 for(int32_t i=1; i<msg_count; i++)
10591 {
10592 if(MsgStrings[i].listpos==index)
10593 {
10594 msglistcache[index-1]=i;
10595 break;
10596 }
10597 }
10598 }
10599
10600 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10601 {
10602 fake_pack_writing=(writecycle==0);
10603 char ebuf[32];
10604
10605 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10606
10607 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10608 {
10609 return qe_invalid;
10610 }
10611
10612 for(int32_t i=1; i<msg_count; i++)
10613 {
10614 int32_t str = msglistcache[i-1];
10615
10616 if(!str)
10617 continue;
10618
10619 if(MsgStrings[str].nextstring != 0)
10620 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10621 else
10622 sprintf(ebuf,"\n\n___%d___\n", str);
10623
10624 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10625 {
10626 return qe_invalid;
10627 }
10628
10629 encode_msg_str(str);
10630
10631 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10632 {
10633 return qe_invalid;
10634 }
10635 }
10636 }
10637
10638 new_return(0);
10639 }
10640
10641 1 int32_t writestrings_tsv(PACKFILE *f)
10642 {
10643 1 std::stringstream ss;
10644
10645 int32_t str;
10646
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10647
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10648 35 encode_msg_str(str);
10649 35 return msgbuf;
10650 }},
10651
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10652
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10654
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10656
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10657
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10658
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10659
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10660
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10661
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10662
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10663
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10664
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10666
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10668
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10671
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10672
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10673
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10674
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10675 };
10676
10677
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10678 {
10679
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10680
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10681 1 break;
10682
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10683 }
10684
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10685
10686 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10687
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10688
10689
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10690 {
10691 35 str = i;
10692 35 auto& msg = MsgStrings[str];
10693
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10694 {
10695
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10696
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10697
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10698 35 break;
10699
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10700
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10701
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10702 35 }
10703
10704
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10705
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10706 {
10707 return qe_invalid;
10708 }
10709
10710 1 new_return(0);
10711 1 }
10712
10713 std::string parse_msg_str(std::string const& s);
10714
10715 void parse_strings_tsv(std::string tsv)
10716 {
10717 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10718 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10719 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10720 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10721 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10722 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10723 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10724 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10725 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10726 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10727 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10728 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10729 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10730 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10731 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10732 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10733 { "margin", [&](auto& msg, auto& text){
10734 std::vector<std::string> strs;
10735 util::split(text, strs, ' ');
10736 if (strs.size() != 4)
10737 throw std::runtime_error("margin field must have 4 components");
10738 msg.margins[0] = std::stoi(strs[0]);
10739 msg.margins[1] = std::stoi(strs[1]);
10740 msg.margins[2] = std::stoi(strs[2]);
10741 msg.margins[3] = std::stoi(strs[3]);
10742 } },
10743 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10744 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10745 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10746 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10747 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10748 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10749 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10750 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10751 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10752 };
10753
10754 std::vector<std::string> rows;
10755 util::split(tsv, rows, '\n');
10756 if (rows.size())
10757 {
10758 std::string last = rows.back();
10759 util::trimstr(last);
10760 if (last.empty())
10761 rows.pop_back();
10762 }
10763 if (rows.size() <= 1)
10764 throw std::runtime_error("missing header row");
10765
10766 std::vector<std::string> columns;
10767 util::split(rows[0], columns, '\t');
10768 for (auto name : columns)
10769 {
10770 if (!fields.contains(name))
10771 throw std::runtime_error(fmt::format("invalid field: {}", name));
10772 }
10773
10774 int start_index = 1;
10775 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10776 start_index += 1;
10777
10778 int num_strings = rows.size() - start_index + 1;
10779 if (num_strings > MAXMSGS-1)
10780 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10781
10782 std::vector<MsgStr> msgs;
10783 msgs.reserve(num_strings);
10784 for (int i = start_index; i < rows.size(); i++)
10785 {
10786 std::vector<std::string> strs;
10787 util::split(rows[i], strs, '\t');
10788 if (strs.size() != columns.size())
10789 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10790
10791 int j = 0;
10792 auto& msg = msgs.emplace_back();
10793 for (auto& name : columns)
10794 {
10795 auto& fn = fields[name];
10796 try
10797 {
10798 fn(msg, strs[j++]);
10799 }
10800 catch (std::exception& ex)
10801 {
10802 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10803 }
10804 }
10805 }
10806
10807 init_msgstrings(0, msgs.size());
10808 for (int i = 0; i < msgs.size(); i++)
10809 MsgStrings[i + 1] = msgs[i];
10810 msg_count = msgs.size();
10811 msglistcache.clear();
10812 }
10813
10814 bool isblanktile(tiledata *buf, int32_t i);
10815 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10816 {
10817 //these are here to bypass compiler warnings about unused arguments
10818 6 version=version;
10819 6 build=build;
10820
10821 int32_t tiles_used;
10822 6 dword section_id=ID_TILES;
10823 6 dword section_version=V_TILES;
10824 6 dword section_cversion=CV_TILES;
10825 6 al_trace("Counting tiles used\n");
10826 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10827
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10828
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10829 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10830 6 dword section_size = 0;
10831
10832 //section id
10833
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10834 {
10835 new_return(1);
10836 }
10837
10838 //section version info
10839
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10840 {
10841 new_return(2);
10842 }
10843
10844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10845 {
10846 new_return(3);
10847 }
10848
10849
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10850 {
10851 12 fake_pack_writing=(writecycle==0);
10852
10853 //section size
10854
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10855 {
10856 new_return(4);
10857 }
10858
10859 12 writesize=0;
10860
10861 //finally... section data
10862 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10863
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10864
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10865
10866
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10867 {
10868 new_return(5);
10869 }
10870
10871
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10872 {
10873
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10874 {
10875
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10876 new_return(8);
10877 238750 }
10878 else
10879 {
10880 209304 int format = newtilebuf[start_tile+i].format;
10881
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10882 {
10883 new_return(6);
10884 }
10885
10886
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10887 {
10888 byte temp_tile[128];
10889 207706 byte *di = temp_tile;
10890 207706 byte *src = newtilebuf[start_tile+i].data;
10891
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10892 {
10893 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10894 26586368 ++di;
10895 26586368 }
10896
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10897 {
10898 new_return(7);
10899 }
10900 207706 }
10901
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10902 {
10903 new_return(7);
10904 }
10905 }
10906 448054 }
10907
10908
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10909 {
10910 6 section_size=writesize;
10911 6 }
10912 12 }
10913
10914
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10915 {
10916 char ebuf[80];
10917 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10918 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10919 }
10920
10921 6 new_return(0);
10922 }
10923
10924 /* MIDI Format
10925 section_id LONG
10926 section_version WORD
10927 section_cversion WORD
10928 section_size LONG
10929 midi_flags 32 Byte ? BITFIELD[252]
10930
10931 [
10932 title 36
10933 start 4
10934 loop_start 4
10935 loop_end 4
10936 loop 2
10937 volume 2
10938 midi *
10939 ]
10940
10941 */
10942
10943 6 int32_t writemidis(PACKFILE *f)
10944 {
10945 6 dword section_id=ID_MIDIS;
10946 6 dword section_version=V_MIDIS;
10947 6 dword section_cversion=CV_MIDIS;
10948 6 dword section_size = 0;
10949
10950 //section id
10951
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10952 {
10953 new_return(1);
10954 }
10955
10956 //section version info
10957
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10958 {
10959 new_return(2);
10960 }
10961
10962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10963 {
10964 new_return(3);
10965 }
10966
10967
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10968 {
10969 12 fake_pack_writing=(writecycle==0);
10970
10971 //section size
10972
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10973 {
10974 new_return(4);
10975 }
10976
10977 12 writesize=0;
10978
10979 //finally... section data
10980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10981 {
10982 new_return(5);
10983 }
10984
10985
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10986 {
10987
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10988 {
10989
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10990 {
10991 new_return(6);
10992 }
10993
10994
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10995 {
10996 new_return(7);
10997 }
10998
10999
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
11000 {
11001 new_return(8);
11002 }
11003
11004
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
11005 {
11006 new_return(9);
11007 }
11008
11009
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
11010 {
11011 new_return(10);
11012 }
11013
11014
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
11015 {
11016 new_return(11);
11017 }
11018
11019
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
11020 {
11021 new_return(12);
11022 }
11023
11024
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].format, sizeof(customtunes[i].format),f))
11025 {
11026 new_return(13);
11027 }
11028
11029
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 switch(customtunes[i].format)
11030 {
11031 case MFORMAT_MIDI:
11032
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!write_midi((MIDI*) customtunes[i].data,f)) new_return(14);
11033
11034 60 break;
11035
11036 default:
11037 new_return(15);
11038 break;
11039 }
11040 60 }
11041 3024 }
11042
11043
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11044 {
11045 6 section_size=writesize;
11046 6 }
11047 12 }
11048
11049
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11050 {
11051 char ebuf[80];
11052 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11053 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11054 }
11055
11056 6 new_return(0);
11057 }
11058
11059 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11060 {
11061 6 dword section_id=ID_CHEATS;
11062 6 dword section_version=V_CHEATS;
11063 6 dword section_cversion=CV_CHEATS;
11064 6 dword section_size = 0;
11065
11066 //section id
11067
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11068 {
11069 new_return(1);
11070 }
11071
11072 //section version info
11073
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11074 {
11075 new_return(2);
11076 }
11077
11078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11079 {
11080 new_return(3);
11081 }
11082
11083
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11084 {
11085 12 fake_pack_writing=(writecycle==0);
11086
11087 //section size
11088
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11089 {
11090 new_return(4);
11091 }
11092
11093 12 writesize=0;
11094
11095 //finally... section data
11096
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11097 {
11098 new_return(5);
11099 }
11100
11101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11102 {
11103
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11104 {
11105 new_return(6);
11106 }
11107
11108
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11109 {
11110 new_return(7);
11111 }
11112 12 }
11113
11114
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11115 {
11116 6 section_size=writesize;
11117 6 }
11118 12 }
11119
11120
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11121 {
11122 char ebuf[80];
11123 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11124 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11125 }
11126
11127 6 new_return(0);
11128 }
11129
11130 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11131 {
11132 //these are here to bypass compiler warnings about unused arguments
11133 6 Header=Header;
11134
11135 6 dword section_id=ID_GUYS;
11136 6 dword section_version=V_GUYS;
11137 6 dword section_cversion=CV_GUYS;
11138 6 dword section_size=0;
11139
11140 //section id
11141
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11142 {
11143 new_return(1);
11144 }
11145
11146 //section version info
11147
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11148 {
11149 new_return(2);
11150 }
11151
11152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11153 {
11154 new_return(3);
11155 }
11156
11157
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11158 {
11159 12 fake_pack_writing=(writecycle==0);
11160
11161 //section size
11162
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11163 {
11164 new_return(4);
11165 }
11166
11167 12 writesize=0;
11168
11169 //finally... section data
11170
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11171 {
11172
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11173 {
11174 new_return(5);
11175 }
11176 6144 }
11177
11178
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6144 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11179 {
11180
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags,f))
11181 {
11182 new_return(6);
11183 }
11184
11185
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags2,f))
11186 {
11187 new_return(7);
11188 }
11189
11190
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11191 {
11192 new_return(8);
11193 }
11194
11195
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11196 {
11197 new_return(9);
11198 }
11199
11200
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11201 {
11202 new_return(10);
11203 }
11204
11205
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11206 {
11207 new_return(11);
11208 }
11209
11210
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11211 {
11212 new_return(12);
11213 }
11214
11215
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11216 {
11217 new_return(13);
11218 }
11219
11220
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11221 {
11222 new_return(14);
11223 }
11224
11225
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11226 {
11227 new_return(15);
11228 }
11229
11230
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11231 {
11232 new_return(16);
11233 }
11234
11235
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11236 {
11237 new_return(17);
11238 }
11239
11240
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11241 {
11242 new_return(18);
11243 }
11244
11245
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11246 {
11247 new_return(19);
11248 }
11249
11250
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11251 {
11252 new_return(20);
11253 }
11254
11255
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11256 {
11257 new_return(21);
11258 }
11259
11260
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11261 {
11262 new_return(22);
11263 }
11264
11265
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11266 {
11267 new_return(23);
11268 }
11269
11270
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11271 {
11272 new_return(24);
11273 }
11274
11275
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11276 {
11277 new_return(25);
11278 }
11279
11280
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11281 {
11282 new_return(26);
11283 }
11284
11285
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11286 {
11287 new_return(27);
11288 }
11289
11290
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11291 {
11292 new_return(28);
11293 }
11294
11295
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11296 {
11297 new_return(29);
11298 }
11299
11300
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11301 {
11302 new_return(30);
11303 }
11304
11305
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11306 {
11307 new_return(31);
11308 }
11309
11310
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11311 {
11312 new_return(32);
11313 }
11314
11315
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11316 {
11317 new_return(33);
11318 }
11319
11320
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11321 {
11322 new_return(34);
11323 }
11324
11325
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11326 {
11327 new_return(35);
11328 }
11329
11330
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11331 {
11332 new_return(36);
11333 }
11334
11335
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11336 {
11337 new_return(37);
11338 }
11339
11340
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11341 {
11342 new_return(38);
11343 }
11344
11345
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11346 {
11347 new_return(39);
11348 }
11349
11350
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11351 {
11352 new_return(40);
11353 }
11354
11355
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11356 {
11357 new_return(41);
11358 }
11359
11360
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11361 {
11362 new_return(42);
11363 }
11364
11365
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11366 {
11367 new_return(43);
11368 }
11369
11370
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11371 {
11372 new_return(44);
11373 }
11374
11375
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11376 {
11377 new_return(45);
11378 }
11379
11380
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11381 {
11382
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11383 {
11384 new_return(46);
11385 }
11386 116736 }
11387
11388
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11389 {
11390 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11391 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11392 //Force SFX_HIT here.
11393
11394 }
11395
11396
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11397 {
11398 new_return(47);
11399 }
11400
11401
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11402 {
11403 new_return(48);
11404 }
11405
11406
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11407 {
11408 new_return(49);
11409 }
11410
11411
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11412 {
11413 new_return(50);
11414 }
11415
11416 //New 2.6 defences
11417
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11418 {
11419
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11420 {
11421 new_return(51);
11422 }
11423 135168 }
11424
11425 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11426
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11427 {
11428 new_return(52);
11429 }
11430
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11431 {
11432 new_return(53);
11433 }
11434
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11435 {
11436 new_return(54);
11437 }
11438
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11439 {
11440 new_return(55);
11441 }
11442
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11443 {
11444 new_return(56);
11445 }
11446 // These are not fixed types, but ints, so they are safe to use here.
11447
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11448 {
11449 new_return(57);
11450 }
11451
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11452 {
11453 new_return(58);
11454 }
11455
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11456 {
11457 new_return(59);
11458 }
11459
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11460 {
11461 new_return(60);
11462 }
11463
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11464 {
11465 new_return(61);
11466 }
11467
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11468 {
11469 new_return(62);
11470 }
11471
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11472 {
11473 new_return(63);
11474 }
11475
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11476 {
11477 new_return(64);
11478 }
11479
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11480 {
11481 new_return(65);
11482 }
11483
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11484 {
11485 new_return(66);
11486 }
11487
11488
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11489 {
11490
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11491 {
11492 new_return(67);
11493 }
11494 61440 }
11495
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11496 {
11497 new_return(68);
11498 }
11499 //misc 16->31
11500
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11501 {
11502 new_return(69);
11503 }
11504
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11505 {
11506 new_return(70);
11507 }
11508
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11509 {
11510 new_return(71);
11511 }
11512
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11513 {
11514 new_return(72);
11515 }
11516
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11517 {
11518 new_return(73);
11519 }
11520
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11521 {
11522 new_return(74);
11523 }
11524
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11525 {
11526 new_return(75);
11527 }
11528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11529 {
11530 new_return(76);
11531 }
11532
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11533 {
11534 new_return(77);
11535 }
11536
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11537 {
11538 new_return(78);
11539 }
11540
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11541 {
11542 new_return(79);
11543 }
11544
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11545 {
11546 new_return(80);
11547 }
11548
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11549 {
11550 new_return(81);
11551 }
11552
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11553 {
11554 new_return(82);
11555 }
11556
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11557 {
11558 new_return(83);
11559 }
11560
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11561 {
11562 new_return(84);
11563 }
11564
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11565 {
11566 new_return(85);
11567 }
11568
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11569 {
11570
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11571 {
11572 new_return(86);
11573 }
11574 196608 }
11575
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11576 {
11577
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11578 {
11579 new_return(87);
11580 }
11581 196608 }
11582
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11583 {
11584 new_return(88);
11585 }
11586
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11587 {
11588
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11589 {
11590 new_return(89);
11591 }
11592 49152 }
11593
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11594 {
11595
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11596 {
11597 new_return(90);
11598 }
11599 12288 }
11600
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11601 {
11602 new_return(91);
11603 }
11604 //somehow forgot these in the older builds -Z
11605
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11606 {
11607 new_return(92);
11608 }
11609
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11610 {
11611 new_return(93);
11612 }
11613
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11614 {
11615 new_return(94);
11616 }
11617
11618 //Enemy Editor InitD[] labels
11619
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11620 {
11621
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11622 {
11623
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11624 {
11625 new_return(95);
11626 }
11627 3194880 }
11628
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11629 {
11630
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11631 {
11632 new_return(96);
11633 }
11634 3194880 }
11635 49152 }
11636
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11637 {
11638 new_return(97);
11639 }
11640 //eweapon initD
11641
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11642 {
11643
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11644 {
11645 new_return(98);
11646 }
11647 49152 }
11648
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11649 new_return(99);
11650
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11651 new_return(100);
11652
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11653 new_return(101);
11654
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11655 new_return(102);
11656 6144 }
11657
11658
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11659 {
11660 6 section_size=writesize;
11661 6 }
11662 12 }
11663
11664
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11665 {
11666 char ebuf[80];
11667 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11668 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11669 }
11670
11671 6 new_return(0);
11672 }
11673
11674 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11675 {
11676 //these are here to bypass compiler warnings about unused arguments
11677 6 Header=Header;
11678
11679 6 dword section_id=ID_HEROSPRITES;
11680 6 dword section_version=V_HEROSPRITES;
11681 6 dword section_cversion=CV_HEROSPRITES;
11682 6 dword section_size=0;
11683
11684 //section id
11685
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11686 {
11687 new_return(1);
11688 }
11689
11690 //section version info
11691
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11692 {
11693 new_return(2);
11694 }
11695
11696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11697 {
11698 new_return(3);
11699 }
11700
11701
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11702 {
11703 12 fake_pack_writing=(writecycle==0);
11704
11705 //section size
11706
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11707 {
11708 new_return(4);
11709 }
11710
11711 12 writesize=0;
11712
11713 //finally... section data
11714
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11715 {
11716
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11717 {
11718 new_return(5);
11719 }
11720
11721
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11722 {
11723 new_return(5);
11724 }
11725
11726
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11727 {
11728 new_return(5);
11729 }
11730 48 }
11731
11732
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11733 {
11734
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11735 {
11736 new_return(6);
11737 }
11738
11739
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11740 {
11741 new_return(6);
11742 }
11743
11744
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11745 {
11746 new_return(6);
11747 }
11748 48 }
11749
11750
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11751 {
11752
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11753 {
11754 new_return(7);
11755 }
11756
11757
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11758 {
11759 new_return(7);
11760 }
11761
11762
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11763 {
11764 new_return(7);
11765 }
11766 48 }
11767
11768
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11769 {
11770
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11771 {
11772 new_return(8);
11773 }
11774
11775
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11776 {
11777 new_return(8);
11778 }
11779
11780
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11781 {
11782 new_return(8);
11783 }
11784 48 }
11785
11786
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11787 {
11788
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11789 {
11790 new_return(8);
11791 }
11792
11793
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11794 {
11795 new_return(8);
11796 }
11797
11798
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11799 {
11800 new_return(8);
11801 }
11802 48 }
11803
11804
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11805 {
11806
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11807 {
11808 new_return(9);
11809 }
11810
11811
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11812 {
11813 new_return(9);
11814 }
11815
11816
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11817 {
11818 new_return(9);
11819 }
11820 48 }
11821
11822
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11823 {
11824
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11825 {
11826 new_return(10);
11827 }
11828
11829
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11830 {
11831 new_return(10);
11832 }
11833
11834
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11835 {
11836 new_return(10);
11837 }
11838 48 }
11839
11840
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11841 {
11842 new_return(11);
11843 }
11844
11845
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11846 {
11847 new_return(11);
11848 }
11849
11850
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11851 {
11852 new_return(11);
11853 }
11854
11855
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11856 {
11857
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11858 {
11859
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11860 {
11861 new_return(12);
11862 }
11863
11864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11865 {
11866 new_return(12);
11867 }
11868
11869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11870 {
11871 new_return(12);
11872 }
11873 72 }
11874 24 }
11875
11876
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11877 {
11878
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11879 {
11880 new_return(13);
11881 }
11882
11883
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11884 {
11885 new_return(13);
11886 }
11887
11888
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11889 {
11890 new_return(13);
11891 }
11892 48 }
11893
11894
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11895 {
11896
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11897 {
11898 new_return(13);
11899 }
11900
11901
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11902 {
11903 new_return(13);
11904 }
11905
11906
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11907 {
11908 new_return(13);
11909 }
11910 48 }
11911
11912
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11913 {
11914 new_return(14);
11915 }
11916
11917 //{ V_HEROSPRITES >= 7
11918
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11919 {
11920
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11921 new_return(15);
11922
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11923 new_return(15);
11924
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11925 new_return(15);
11926 48 }
11927
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11928 {
11929
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11930 new_return(15);
11931
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11932 new_return(15);
11933
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11934 new_return(15);
11935 48 }
11936
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11937 {
11938
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11939 new_return(15);
11940
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11941 new_return(15);
11942
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11943 new_return(15);
11944 48 }
11945
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11946 {
11947
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11948 new_return(15);
11949
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11950 new_return(15);
11951
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11952 new_return(15);
11953 48 }
11954
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11955 {
11956
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11957 new_return(15);
11958
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11959 new_return(15);
11960
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11961 new_return(15);
11962 48 }
11963
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11964 {
11965
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11966 new_return(15);
11967
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11968 new_return(15);
11969
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11970 new_return(15);
11971 48 }
11972
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11973 {
11974
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11975 new_return(15);
11976
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11977 new_return(15);
11978
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11979 new_return(15);
11980 48 }
11981
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11982 {
11983
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11984 new_return(15);
11985
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11986 new_return(15);
11987
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11988 new_return(15);
11989 48 }
11990
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11991 {
11992
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11993 new_return(15);
11994
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11995 new_return(15);
11996
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11997 new_return(15);
11998
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11999 new_return(15);
12000 48 }
12001
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12002 {
12003
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
12004 new_return(15);
12005
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
12006 new_return(15);
12007
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
12008 new_return(15);
12009 48 }
12010
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12011 {
12012
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
12013 new_return(15);
12014
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12015 new_return(15);
12016
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12017 new_return(15);
12018 48 }
12019
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12020 {
12021
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12022 new_return(15);
12023
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12024 new_return(15);
12025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12026 new_return(15);
12027 48 }
12028
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12029 {
12030
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12031 new_return(15);
12032
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12033 new_return(15);
12034
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12035 new_return(15);
12036 48 }
12037
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12038 {
12039
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12040 new_return(15);
12041
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12042 new_return(15);
12043
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12044 new_return(15);
12045 48 }
12046
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12047 {
12048
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12049 new_return(15);
12050
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12051 new_return(15);
12052
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12053 new_return(15);
12054 48 }
12055
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12056 {
12057
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12058 new_return(15);
12059
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12060 new_return(15);
12061
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12062 new_return(15);
12063 48 }
12064
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12065 {
12066
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12067 new_return(15);
12068
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12069 new_return(15);
12070
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12071 new_return(15);
12072 48 }
12073
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12074 {
12075
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12076 new_return(15);
12077
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12078 new_return(15);
12079
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12080 new_return(15);
12081 48 }
12082
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12083 {
12084
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12085 new_return(15);
12086
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12087 new_return(15);
12088
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12089 new_return(15);
12090 48 }
12091
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12092 {
12093
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12094 new_return(15);
12095
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12096 new_return(15);
12097
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12098 new_return(15);
12099 48 }
12100
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12101 {
12102
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12103 new_return(15);
12104
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12105 new_return(15);
12106
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12107 new_return(15);
12108 48 }
12109
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12110 {
12111
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12112 new_return(15);
12113
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12114 new_return(15);
12115
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12116 new_return(15);
12117 48 }
12118
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12119 {
12120
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12121 new_return(15);
12122
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12123 new_return(15);
12124
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12125 new_return(15);
12126 48 }
12127
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12128 {
12129
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12130 new_return(15);
12131
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12132 new_return(15);
12133
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12134 new_return(15);
12135 36 }
12136
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12137 {
12138
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12139 new_return(16);
12140
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12141 new_return(16);
12142
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12143 new_return(16);
12144 48 }
12145
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12146 {
12147
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12148 new_return(17);
12149
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12150 new_return(17);
12151
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12152 new_return(17);
12153 48 }
12154
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12155 {
12156
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12157 new_return(17);
12158
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12159 new_return(17);
12160
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12161 new_return(17);
12162 48 }
12163
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12164 {
12165
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12166 new_return(17);
12167
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12168 new_return(17);
12169
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12170 new_return(17);
12171 48 }
12172
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12173 {
12174
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12175 new_return(18);
12176
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12177 new_return(18);
12178
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12179 new_return(18);
12180 48 }
12181
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12182 {
12183
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12184 new_return(19);
12185 48 }
12186
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12187 {
12188
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12189 new_return(20);
12190
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12191 new_return(20);
12192
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12193 new_return(20);
12194 36 }
12195
12196
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12197 {
12198 new_return(21);
12199 }
12200
12201
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12202 {
12203 new_return(21);
12204 }
12205
12206
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12207 {
12208 new_return(21);
12209 }
12210
12211
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12212 {
12213
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12214 new_return(22);
12215
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12216 new_return(22);
12217
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12218 new_return(22);
12219 48 }
12220
12221
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12222 {
12223
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12224 {
12225 new_return(23);
12226 }
12227
12228
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12229 {
12230 new_return(23);
12231 }
12232
12233
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12234 {
12235 new_return(23);
12236 }
12237 48 }
12238
12239
12240
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12241 {
12242
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12243 new_return(15);
12244 1752 }
12245 //}
12246
12247
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12248 {
12249 6 section_size=writesize;
12250 6 }
12251 12 }
12252
12253 //More data will come here
12254
12255
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12256 {
12257 char ebuf[80];
12258 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12259 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12260 }
12261
12262 6 new_return(0);
12263 }
12264
12265 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12266 {
12267 6 dword section_id=ID_SUBSCREEN;
12268 6 dword section_version=V_SUBSCREEN;
12269 6 dword section_cversion=CV_SUBSCREEN;
12270 6 dword section_size=0;
12271
12272 //section id
12273
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12274 {
12275 new_return(1);
12276 }
12277
12278 //section version info
12279
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12280 {
12281 new_return(2);
12282 }
12283
12284
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12285 {
12286 new_return(3);
12287 }
12288
12289
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12290 {
12291 12 fake_pack_writing=(writecycle==0);
12292
12293 //section size
12294
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12295 {
12296 new_return(4);
12297 }
12298
12299 12 writesize=0;
12300
12301 12 byte sz = subscreens_active.size();
12302
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12303 new_return(5);
12304
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12305 {
12306 66 int32_t ret = subscreens_active[i].write(f);
12307 66 fake_pack_writing=(writecycle==0);
12308
12309
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12310 new_return(ret);
12311 66 }
12312
12313 12 sz = subscreens_passive.size();
12314
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12315 new_return(5);
12316
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12317 {
12318 50 int32_t ret = subscreens_passive[i].write(f);
12319 50 fake_pack_writing=(writecycle==0);
12320
12321
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12322 new_return(ret);
12323 50 }
12324
12325 12 sz = subscreens_overlay.size();
12326
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12327 new_return(5);
12328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12329 {
12330 int32_t ret = subscreens_overlay[i].write(f);
12331 fake_pack_writing=(writecycle==0);
12332
12333 if(ret!=0)
12334 new_return(ret);
12335 }
12336
12337
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12338 {
12339 6 section_size=writesize;
12340 6 }
12341 12 }
12342
12343
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12344 {
12345 char ebuf[80];
12346 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12347 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12348 }
12349
12350 6 new_return(0);
12351 6 }
12352
12353 extern script_data *ffscripts[NUMSCRIPTFFC];
12354 extern script_data *itemscripts[NUMSCRIPTITEM];
12355 extern script_data *guyscripts[NUMSCRIPTGUYS];
12356 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12357 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12358 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12359 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12360 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12361 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12362 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12363 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12364 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12365 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12366
12367 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12368 {
12369 6 dword section_id = ID_FFSCRIPT;
12370 6 dword section_version = V_FFSCRIPT;
12371 6 dword section_cversion = CV_FFSCRIPT;
12372 6 dword section_size = 0;
12373 6 dword zasmmeta_version = METADATA_V;
12374 6 byte numscripts = 0;
12375 6 numscripts = numscripts; //to avoid unused variables warnings
12376
12377 //section id
12378
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12379 {
12380 new_return(1);
12381 }
12382
12383 //section version info
12384
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12385 {
12386 new_return(2);
12387 }
12388
12389
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12390 {
12391 new_return(3);
12392 }
12393
12394
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12395 {
12396 new_return(4);
12397 }
12398
12399
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12400 {
12401 12 fake_pack_writing=(writecycle==0);
12402
12403 //section size
12404
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12405 {
12406 new_return(5);
12407 }
12408
12409 12 writesize=0;
12410
12411
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12412 {
12413 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12414 6144 fake_pack_writing=(writecycle==0);
12415
12416
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12417 {
12418 new_return(ret);
12419 }
12420 6144 }
12421
12422
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12423 {
12424 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12425 3072 fake_pack_writing=(writecycle==0);
12426
12427
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12428 {
12429 new_return(ret);
12430 }
12431 3072 }
12432
12433
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12434 {
12435 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12436 3072 fake_pack_writing=(writecycle==0);
12437
12438
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12439 {
12440 new_return(ret);
12441 }
12442 3072 }
12443
12444
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12445
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12446 {
12447 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12448 3072 fake_pack_writing=(writecycle==0);
12449
12450
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12451 {
12452 new_return(ret);
12453 }
12454 3072 }
12455
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12456
12457
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12458 {
12459 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12460 3072 fake_pack_writing=(writecycle==0);
12461
12462
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12463 {
12464 new_return(ret);
12465 }
12466 3072 }
12467
12468
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12469 {
12470 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12471 96 fake_pack_writing=(writecycle==0);
12472
12473
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12474 {
12475 new_return(ret);
12476 }
12477 96 }
12478
12479
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12480 {
12481 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12482 60 fake_pack_writing=(writecycle==0);
12483
12484
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12485 {
12486 new_return(ret);
12487 }
12488 60 }
12489
12490
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12491 {
12492 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12493 3072 fake_pack_writing=(writecycle==0);
12494
12495
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12496 {
12497 new_return(ret);
12498 }
12499 3072 }
12500
12501
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12502 {
12503 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12504 3072 fake_pack_writing=(writecycle==0);
12505
12506
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12507 {
12508 new_return(ret);
12509 }
12510 3072 }
12511
12512
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12513 {
12514 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12515 3072 fake_pack_writing=(writecycle==0);
12516
12517
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12518 {
12519 new_return(ret);
12520 }
12521 3072 }
12522
12523
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12524 {
12525 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12526 3072 fake_pack_writing=(writecycle==0);
12527
12528
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12529 {
12530 new_return(ret);
12531 }
12532 3072 }
12533
12534
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12535 {
12536 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12537 6144 fake_pack_writing=(writecycle==0);
12538
12539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12540 {
12541 new_return(ret);
12542 }
12543 6144 }
12544
12545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12546 {
12547 new_return(2000);
12548 }
12549
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12550 {
12551 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12552 6144 fake_pack_writing=(writecycle==0);
12553
12554
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12555 {
12556 new_return(ret);
12557 }
12558 6144 }
12559
12560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12561 {
12562 new_return(2001);
12563 }
12564
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12565 {
12566 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12567 3072 fake_pack_writing=(writecycle==0);
12568
12569
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12570 {
12571 new_return(ret);
12572 }
12573 3072 }
12574
12575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12576 {
12577 new_return(2001);
12578 }
12579
12580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12581 {
12582 new_return(2002);
12583 }
12584
12585 12 word numffcbindings=0;
12586
12587
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12588 {
12589
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12590 {
12591 200 numffcbindings++;
12592 200 }
12593 6132 }
12594
12595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12596 {
12597 new_return(2003);
12598 }
12599
12600
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12601 {
12602
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12603 {
12604
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12605 {
12606 new_return(2004);
12607 }
12608
12609
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12610 {
12611 new_return(2005);
12612 }
12613
12614
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12615 {
12616 new_return(2006);
12617 }
12618 200 }
12619 6132 }
12620
12621 12 word numglobalbindings=0;
12622
12623
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12624 {
12625
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12626 {
12627 24 numglobalbindings++;
12628 24 }
12629 96 }
12630
12631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12632 {
12633 new_return(2007);
12634 }
12635
12636
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12637 {
12638
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12639 {
12640
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12641 {
12642 new_return(2008);
12643 }
12644
12645
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12646 {
12647 new_return(2009);
12648 }
12649
12650
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12651 {
12652 new_return(2010);
12653 }
12654 24 }
12655 96 }
12656
12657 12 word numitembindings=0;
12658
12659
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12660 {
12661
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12662 {
12663 24 numitembindings++;
12664 24 }
12665 3060 }
12666
12667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12668 {
12669 new_return(2011);
12670 }
12671
12672
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12673 {
12674
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12675 {
12676
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12677 {
12678 new_return(2012);
12679 }
12680
12681
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12682 {
12683 new_return(2013);
12684 }
12685
12686
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12687 {
12688 new_return(2014);
12689 }
12690 24 }
12691 3060 }
12692
12693 //new script types
12694 //npc scripts
12695 12 word numnpcbindings=0;
12696
12697
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12698 {
12699
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12700 {
12701 numnpcbindings++;
12702 }
12703 3060 }
12704
12705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12706 {
12707 new_return(2015);
12708 }
12709
12710
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12711 {
12712
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12713 {
12714 if(!p_iputw(it->first,f))
12715 {
12716 new_return(2016);
12717 }
12718
12719 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12720 {
12721 new_return(2017);
12722 }
12723
12724 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12725 {
12726 new_return(2018);
12727 }
12728 }
12729 3060 }
12730
12731 //lweapon
12732
12733 12 word numlwpnbindings=0;
12734
12735
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12736 {
12737
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12738 {
12739 numlwpnbindings++;
12740 }
12741 3060 }
12742
12743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12744 {
12745 new_return(2019);
12746 }
12747
12748
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12749 {
12750
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12751 {
12752 if(!p_iputw(it->first,f))
12753 {
12754 new_return(2020);
12755 }
12756
12757 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12758 {
12759 new_return(2021);
12760 }
12761
12762 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12763 {
12764 new_return(2022);
12765 }
12766 }
12767 3060 }
12768
12769 //////
12770
12771 //eweapon
12772
12773
12774 12 word numewpnbindings=0;
12775
12776
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12777 {
12778
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12779 {
12780 numewpnbindings++;
12781 }
12782 3060 }
12783
12784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12785 {
12786 new_return(2023);
12787 }
12788
12789
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12790 {
12791
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12792 {
12793 if(!p_iputw(it->first,f))
12794 {
12795 new_return(2024);
12796 }
12797
12798 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12799 {
12800 new_return(2025);
12801 }
12802
12803 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12804 {
12805 new_return(2026);
12806 }
12807 }
12808 3060 }
12809
12810 //player scripts
12811 12 word numherobindings=0;
12812
12813
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12814 {
12815
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12816 {
12817 2 numherobindings++;
12818 2 }
12819 48 }
12820
12821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12822 {
12823 new_return(2027);
12824 }
12825
12826
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12827 {
12828
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12829 {
12830
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12831 {
12832 new_return(2028);
12833 }
12834
12835
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12836 {
12837 new_return(2029);
12838 }
12839
12840
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12841 {
12842 new_return(2030);
12843 }
12844 2 }
12845 48 }
12846
12847 //dmap scripts
12848 12 word numdmapbindings=0;
12849
12850
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12851 {
12852
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12853 {
12854 4 numdmapbindings++;
12855 4 }
12856 3060 }
12857
12858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12859 {
12860 new_return(2031);
12861 }
12862
12863
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12864 {
12865
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12866 {
12867
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12868 {
12869 new_return(2032);
12870 }
12871
12872
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12873 {
12874 new_return(2033);
12875 }
12876
12877
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12878 {
12879 new_return(2034);
12880 }
12881 4 }
12882 3060 }
12883
12884 //screen scripts
12885 12 word numscreenbindings=0;
12886
12887
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12888 {
12889
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12890 {
12891 16 numscreenbindings++;
12892 16 }
12893 3060 }
12894
12895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12896 {
12897 new_return(2035);
12898 }
12899
12900
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12901 {
12902
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12903 {
12904
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12905 {
12906 new_return(2036);
12907 }
12908
12909
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12910 {
12911 new_return(2037);
12912 }
12913
12914
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12915 {
12916 new_return(2038);
12917 }
12918 16 }
12919 3060 }
12920 //item sprite scripts
12921 12 word numitemspritebindings=0;
12922
12923
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12924 {
12925
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12926 {
12927 numitemspritebindings++;
12928 }
12929 3060 }
12930
12931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12932 {
12933 new_return(2039);
12934 }
12935
12936
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12937 {
12938
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12939 {
12940 if(!p_iputw(it->first,f))
12941 {
12942 new_return(2040);
12943 }
12944
12945 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12946 {
12947 new_return(2041);
12948 }
12949
12950 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12951 {
12952 new_return(2042);
12953 }
12954 }
12955 3060 }
12956
12957 //combo scripts
12958 12 word numcombobindings=0;
12959
12960
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12961 {
12962
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12963 {
12964 numcombobindings++;
12965 }
12966 6132 }
12967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12968 {
12969 new_return(2043);
12970 }
12971
12972
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12973 {
12974
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12975 {
12976 if(!p_iputw(it->first,f))
12977 {
12978 new_return(2044);
12979 }
12980
12981 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12982 {
12983 new_return(2045);
12984 }
12985
12986 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12987 {
12988 new_return(2046);
12989 }
12990 }
12991 6132 }
12992 //subscreen scripts
12993 12 word numgenericbindings=0;
12994
12995
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12996 {
12997
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12998 {
12999 numgenericbindings++;
13000 }
13001 6132 }
13002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
13003 {
13004 new_return(2043);
13005 }
13006
13007
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13008 {
13009
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13010 {
13011 if(!p_iputw(it->first,f))
13012 {
13013 new_return(2044);
13014 }
13015
13016 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13017 {
13018 new_return(2045);
13019 }
13020
13021 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13022 {
13023 new_return(2046);
13024 }
13025 }
13026 6132 }
13027
13028 //generic scripts
13029 12 word numsubscreenbindings=0;
13030
13031
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13032 {
13033
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13034 {
13035 numsubscreenbindings++;
13036 }
13037 3060 }
13038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13039 {
13040 new_return(2047);
13041 }
13042
13043
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13044 {
13045
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13046 {
13047 if(!p_iputw(it->first,f))
13048 {
13049 new_return(2048);
13050 }
13051
13052 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13053 {
13054 new_return(2049);
13055 }
13056
13057 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13058 {
13059 new_return(2050);
13060 }
13061 }
13062 3060 }
13063
13064
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13065 {
13066 6 section_size=writesize;
13067 6 }
13068 12 }
13069
13070
13071
13072
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13073 {
13074 char ebuf[80];
13075 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13076 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13077 }
13078
13079 6 new_return(0);
13080 //return 0; //this is just here to stomp the compiler from whining.
13081 //the irony is that it causes an "unreachable code" warning.
13082 6 }
13083
13084 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13085 {
13086 //these are here to bypass compiler warnings about unused arguments
13087 46236 Header=Header;
13088 46236 i=i;
13089
13090
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13091
13092
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13093 {
13094 new_return(6);
13095 }
13096
13097 //Metadata
13098 46236 zasm_meta const& tmeta = (*script)->meta;
13099
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13100 {
13101 new_return(7);
13102 }
13103
13104
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13105 {
13106 new_return(8);
13107 }
13108
13109
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13110 {
13111 new_return(9);
13112 }
13113
13114
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13115 {
13116 new_return(10);
13117 }
13118
13119
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13120 {
13121
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13122 new_return(11);
13123 369888 }
13124
13125
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13126 {
13127
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13128 {
13129 new_return(12);
13130 }
13131 369888 }
13132
13133
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13134 {
13135 new_return(13);
13136 }
13137
13138
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13139 {
13140 new_return(14);
13141 }
13142
13143
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13144 {
13145 new_return(15);
13146 }
13147
13148
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13149 {
13150 new_return(16);
13151 }
13152
13153
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13154 {
13155 new_return(17);
13156 }
13157
13158
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13159 new_return(18);
13160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13161 new_return(19);
13162
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13163 {
13164
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13165 new_return(27);
13166
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13167 new_return(28);
13168 462360 }
13169
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13170 {
13171
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13172 new_return(29);
13173
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13174 new_return(30);
13175 369888 }
13176
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13177 {
13178
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13179 new_return(31);
13180
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13181 new_return(32);
13182 369888 }
13183
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13184 {
13185
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13186 new_return(33);
13187
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13188 new_return(34);
13189 739776 }
13190
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13191 {
13192
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13193 new_return(35);
13194
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13195 new_return(36);
13196 369888 }
13197
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13198 {
13199
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13200 new_return(37);
13201 369888 }
13202
13203
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626442 times.
663184 for(int32_t j=0; j<num_commands; j++)
13204 {
13205 626442 auto& zas = (*script)->zasm_script->zasm[j];
13206
1/2
✓ Branch 0 taken 626442 times.
✗ Branch 1 not taken.
626442 if(!p_iputw(zas.command,f))
13207 {
13208 new_return(20);
13209 }
13210
13211
2/2
✓ Branch 0 taken 616948 times.
✓ Branch 1 taken 9494 times.
626442 if(zas.command==0xFFFF)
13212 {
13213 9494 break;
13214 }
13215 else
13216 {
13217
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg1,f))
13218 {
13219 new_return(21);
13220 }
13221
13222
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg2,f))
13223 {
13224 new_return(22);
13225 }
13226
13227
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg3,f))
13228 {
13229 new_return(23);
13230 }
13231
13232 616948 uint32_t sz = 0;
13233
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614178 times.
616948 if(zas.strptr)
13234 2770 sz = zas.strptr->size();
13235
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13236 {
13237 new_return(23);
13238 }
13239
2/2
✓ Branch 0 taken 614178 times.
✓ Branch 1 taken 2770 times.
616948 if(sz)
13240 {
13241 2770 auto& str = *zas.strptr;
13242
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13243 {
13244
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13245 {
13246 new_return(24);
13247 }
13248 222648 }
13249 2770 }
13250 616948 sz = 0;
13251
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(zas.vecptr)
13252 114 sz = zas.vecptr->size();
13253
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13254 {
13255 new_return(25);
13256 }
13257
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(sz) //vector found
13258 {
13259 114 auto& vec = *zas.vecptr;
13260
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13261 {
13262
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13263 {
13264 new_return(26);
13265 }
13266 850 }
13267 114 }
13268 }
13269 616948 }
13270
13271 46236 new_return(0);
13272 }
13273
13274 extern SAMPLE customsfxdata[WAV_COUNT];
13275 extern uint8_t customsfxflag[WAV_COUNT>>3];
13276
13277 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13278 {
13279 //these are here to bypass compiler warnings about unused arguments
13280 6 Header=Header;
13281
13282 6 dword section_id=ID_SFX;
13283 6 dword section_version=V_SFX;
13284 6 dword section_cversion=CV_SFX;
13285 6 dword section_size=0;
13286
13287 //section id
13288
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13289 {
13290 new_return(1);
13291 }
13292
13293 //section version info
13294
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13295 {
13296 new_return(2);
13297 }
13298
13299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13300 {
13301 new_return(3);
13302 }
13303
13304
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13305 {
13306 12 fake_pack_writing=(writecycle==0);
13307
13308 //section size
13309
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13310 {
13311 new_return(4);
13312 }
13313
13314 12 writesize=0;
13315
13316
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13317 {
13318
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13319 {
13320 new_return(5);
13321 }
13322 384 }
13323
13324
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13325 {
13326
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13327 2240 continue;
13328
13329
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13330 {
13331 new_return(5);
13332 }
13333 820 }
13334
13335
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13336 {
13337
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13338 2240 continue;
13339
13340
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13341 {
13342 new_return(5);
13343 }
13344
13345
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13346 {
13347 new_return(6);
13348 }
13349
13350
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13351 {
13352 new_return(7);
13353 }
13354
13355
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13356 {
13357 new_return(8);
13358 }
13359
13360
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13361 {
13362 new_return(9);
13363 }
13364
13365
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13366 {
13367 new_return(10);
13368 }
13369
13370
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13371 {
13372 new_return(11);
13373 }
13374
13375
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13376 {
13377 new_return(12);
13378 }
13379
13380 //de-endianfy the data
13381 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13382
13383
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13384 {
13385
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13386 {
13387 new_return(13);
13388 }
13389 18594894 }
13390 820 }
13391
13392
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13393 {
13394 6 section_size=writesize;
13395 6 }
13396 12 }
13397
13398
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13399 {
13400 char ebuf[80];
13401 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13402 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13403 }
13404
13405 6 new_return(0);
13406 }
13407
13408 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13409 {
13410 6 dword section_id=ID_INITDATA;
13411 6 dword section_version=V_INITDATA;
13412 6 dword section_cversion=CV_INITDATA;
13413 6 dword section_size = 0;
13414
13415 6 zinit.last_map=Map.getCurrMap();
13416 6 zinit.last_screen=Map.getCurrScr();
13417 6 zinit.normalize();
13418
13419 //section id
13420
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13421 {
13422 new_return(1);
13423 }
13424
13425 //section version info
13426
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13427 {
13428 new_return(2);
13429 }
13430
13431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13432 {
13433 new_return(3);
13434 }
13435
13436 //TODO
13437
13438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13439 {
13440 12 fake_pack_writing=(writecycle==0);
13441
13442 //section size
13443
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13444 new_return(4);
13445
13446 12 writesize=0;
13447
13448
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13449
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13450 new_return(5);
13451
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13452 {
13453
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13454 new_return(6);
13455
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13456 new_return(7);
13457
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13458 new_return(8);
13459
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13460 new_return(9);
13461 768 }
13462
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13463 new_return(10);
13464
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13465 new_return(11);
13466
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13467
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13468 new_return(12);
13469
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13470
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13471 new_return(13);
13472
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13473 new_return(14);
13474
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13475 new_return(15);
13476
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13477 new_return(16);
13478
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13479 new_return(17);
13480
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13481 new_return(18);
13482
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13483 new_return(19);
13484
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13485 new_return(20);
13486
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13487 new_return(21);
13488
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13489 new_return(22);
13490
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13491 new_return(23);
13492
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13493 new_return(24);
13494
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13495 new_return(25);
13496
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13497 new_return(26);
13498
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13499 new_return(27);
13500
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13501 new_return(28);
13502
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13503 new_return(29);
13504
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13505 new_return(30);
13506
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13507 new_return(31);
13508
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13509 new_return(32);
13510
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13511 new_return(33);
13512
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13513 new_return(34);
13514
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13515 new_return(35);
13516
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13517 new_return(36);
13518
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13519 new_return(37);
13520
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13521 new_return(38);
13522
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13523 new_return(39);
13524
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13525 new_return(40);
13526
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13527 new_return(41);
13528
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13529 new_return(42);
13530
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13531 new_return(43);
13532
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13533 new_return(44);
13534
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13535 new_return(45);
13536
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13537 new_return(46);
13538
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13539 new_return(47);
13540
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13541 new_return(48);
13542
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13543 new_return(49);
13544
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13545 new_return(50);
13546
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13547 new_return(51);
13548
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13549 new_return(52);
13550
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13551 new_return(53);
13552
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13553 new_return(54);
13554
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13555 new_return(55);
13556
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13557 new_return(56);
13558
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13559 new_return(57);
13560
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13561 new_return(58);
13562
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13563 new_return(59);
13564
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13565 new_return(60);
13566
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13567 new_return(61);
13568
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13569 new_return(62);
13570
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13571 new_return(63);
13572
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13573 new_return(64);
13574
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13575 new_return(65);
13576
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13577 new_return(66);
13578
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13579 new_return(67);
13580
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13581 new_return(68);
13582
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13583 new_return(69);
13584
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13585 new_return(70);
13586
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13587 new_return(71);
13588
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13589 new_return(72);
13590
13591
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13592 {
13593 6 section_size=writesize;
13594 6 }
13595 12 }
13596
13597
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13598 {
13599 char ebuf[80];
13600 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13601 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13602 }
13603
13604 6 new_return(0);
13605 }
13606
13607 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13608 {
13609 //these are here to bypass compiler warnings about unused arguments
13610 6 Header=Header;
13611
13612 6 dword section_id=ID_ITEMDROPSETS;
13613 6 dword section_version=V_ITEMDROPSETS;
13614 6 dword section_cversion=CV_ITEMDROPSETS;
13615 // dword section_size=0;
13616 6 dword section_size = 0;
13617 6 word num_item_drop_sets=count_item_drop_sets();
13618
13619 //section id
13620
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13621 {
13622 new_return(1);
13623 }
13624
13625 //section version info
13626
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13627 {
13628 new_return(2);
13629 }
13630
13631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13632 {
13633 new_return(3);
13634 }
13635
13636
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13637 {
13638 12 fake_pack_writing=(writecycle==0);
13639
13640 //section size
13641
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13642 {
13643 new_return(4);
13644 }
13645
13646 12 writesize=0;
13647
13648 //finally... section data
13649
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13650 {
13651 new_return(5);
13652 }
13653
13654
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13655 {
13656
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13657 {
13658 new_return(6);
13659 }
13660
13661
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13662 {
13663
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13664 {
13665 new_return(7);
13666 }
13667 1580 }
13668
13669
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13670 {
13671
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13672 {
13673 new_return(8);
13674 }
13675 1738 }
13676 158 }
13677
13678
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13679 {
13680 6 section_size=writesize;
13681 6 }
13682 12 }
13683
13684
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13685 {
13686 char ebuf[80];
13687 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13688 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13689 }
13690
13691 6 new_return(0);
13692 }
13693
13694 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13695 {
13696 6 dword section_id=ID_FAVORITES;
13697 6 dword section_version=V_FAVORITES;
13698 6 dword section_cversion=CV_FAVORITES;
13699 6 dword section_size = 0;
13700
13701 //section id
13702
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13703 {
13704 new_return(1);
13705 }
13706
13707 //section version info
13708
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13709 {
13710 new_return(2);
13711 }
13712
13713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13714 {
13715 new_return(3);
13716 }
13717
13718
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13719 {
13720 12 fake_pack_writing=(writecycle==0);
13721
13722 //section size
13723
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13724 new_return(4);
13725
13726 12 writesize=0;
13727
13728
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13729 new_return(16);
13730
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13731 new_return(17);
13732
13733 12 word favcmb_cnt = 0;
13734
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13735
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13736 {
13737 8 favcmb_cnt = q+1;
13738 8 break;
13739 }
13740
13741
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13742 new_return(5);
13743
13744
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13745 {
13746
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13747 new_return(6);
13748
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13749 new_return(7);
13750 210 }
13751
13752
13753 12 word max_combo_cols = MAX_COMBO_COLS;
13754
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13755 new_return(9);
13756
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13757 {
13758
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13759 new_return(10);
13760
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13761 new_return(11);
13762
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13763 new_return(12);
13764 48 }
13765 12 word max_mappages = MAX_MAPPAGE_BTNS;
13766
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13767 new_return(13);
13768
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13769 {
13770
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13771 new_return(14);
13772
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13773 new_return(15);
13774 108 }
13775
13776
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13777 {
13778 6 section_size=writesize;
13779 6 }
13780 12 }
13781
13782
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13783 {
13784 char ebuf[80];
13785 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13786 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13787 }
13788
13789 6 new_return(0);
13790 }
13791
13792 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13793 {
13794
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13795 6 reset_combo_animations();
13796 6 reset_combo_animations2();
13797 6 strcpy(header.id_str,QH_NEWIDSTR);
13798 6 header.zelda_version = ZELDA_VERSION;
13799 6 header.internal = INTERNAL_VERSION;
13800 // header.str_count = msg_count;
13801 // header.data_flags[ZQ_TILES] = usetiles;
13802 6 header.data_flags[ZQ_TILES] = true;
13803 6 header.data_flags[ZQ_CHEATS2] = 1;
13804 6 header.build=VERSION_BUILD;
13805
13806
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13807 {
13808 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13809 1512 }
13810
13811 char zinfofilename[2048];
13812 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13813
13814 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13815 6 box_out("Saving Quest...");
13816 6 box_eol();
13817 6 box_eol();
13818
13819
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13820
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13821
13822
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13823 return 1;
13824
13825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13826
13827
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13828 return 2;
13829
13830
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13831
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13832
13833
13834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13835 {
13836 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13837
13838 box_out("Writing ZInfo...");
13839 if(inf)
13840 {
13841 if(writezinfo(inf,ZI)!=0)
13842 return 2;
13843
13844 pack_fclose(inf);
13845 box_out("okay.");
13846 }
13847 else box_out(" ...file failure");
13848 box_eol();
13849 }
13850 else
13851 {
13852
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13853
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13854 return 2;
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13856
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13857 }
13858
13859
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13861
13862
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13863 return 3;
13864
13865
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13866
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13867
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13869
13870
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13871 return 4;
13872
13873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13874
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13875
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13877
13878
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13879 return 5;
13880
13881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13882
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13883
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13885
13886
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13887 return 6;
13888
13889
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13890
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13891
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13893
13894
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13895 return 7;
13896
13897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13898
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13899
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13901
13902
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13903 return 8;
13904
13905
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13906
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13907
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13909
13910
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13911 return 9;
13912
13913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13914
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13915
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13917
13918
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13919 return 10;
13920
13921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13923
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13925
13926
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13927 return 11;
13928
13929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13930
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13931
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13933
13934
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13935 return 12;
13936
13937
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13938
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13939
13940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13941
13942
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13943 return 13;
13944
13945
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13946
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13947
13948
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13949
13950
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13951 return 14;
13952
13953
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13954
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13955
13956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13957
13958
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13959 return 15;
13960
13961
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13963
13964
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13965
13966
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13967 return 16;
13968
13969
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13970
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13971
13972
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13973
13974
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13975 return 17;
13976
13977
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13978
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13979
13980
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13981
13982
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13983 return 18;
13984
13985
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13986
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13987
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13989
13990
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13991 return 19;
13992
13993
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13994
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13995
13996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13997
13998
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13999 return 20;
14000
14001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14003
14004
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
14005
14006
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
14007 return 21;
14008
14009
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14010
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14011
14012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
14013
14014
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14015 return 22;
14016
14017
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14018
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14019
14020
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14021
14022
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14023 return 23;
14024
14025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14026
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14027
14028
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14029
14030
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14031 return 24;
14032
14033
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14034
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14035
14036
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14037
14038
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14039 return 25;
14040
14041
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14042
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14043
14044
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14045
14046
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14047 return 26;
14048
14049
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14050
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14051
14052
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14053
14054
14055
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14056 {
14057 char const* kfname = filename;
14058 char keyfilename[2048]={0};
14059 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14060
14061 char temp_pw[QSTPWD_LEN] = {0};
14062 uint ind = 0;
14063 for(char const* ext : {"key","zpwd","zcheat"})
14064 {
14065 replace_extension(keyfilename, kfname, ext, 2047);
14066 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14067 char msg[80] = {0};
14068 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14069 msg[78]=13;
14070 msg[79]=10;
14071 pfwrite(msg, 80, fp);
14072 p_iputw(header.zelda_version,fp);
14073 p_putc(header.build,fp);
14074 char const* pwd = header.password;
14075 if(ind == 2) //.zcheat, hashed pwd
14076 {
14077 char hashmap = 'Z';
14078 hashmap += 'Q';
14079 hashmap += 'U';
14080 hashmap += 'E';
14081 hashmap += 'S';
14082 hashmap += 'T';
14083 for ( int q = 0; q < QSTPWD_LEN; ++q )
14084 {
14085 temp_pw[q] = header.password[q];
14086 temp_pw[q] += hashmap;
14087 }
14088 pwd = temp_pw;
14089 }
14090 pfwrite(pwd, strlen(pwd), fp);
14091 pack_fclose(fp);
14092 ++ind;
14093 }
14094 }
14095
14096 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14097 6 std::error_code ec;
14098
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14100 {
14101 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14102 return ec.value();
14103 }
14104
14105
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14106
14107 #ifdef __EMSCRIPTEN__
14108 em_sync_fs();
14109 #endif
14110
14111 6 return 0;
14112 6 }
14113
14114 // #ifdef _WIN32
14115 // static std::time_t to_time_t(FILETIME const& ft) {
14116 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14117 // t -= 116444736000000000ull;
14118 // t /= 10000000u;
14119 // return static_cast<std::time_t>(t);
14120 // }
14121 // #else
14122 // #endif
14123 template<typename TP>
14124 4 static std::time_t to_time_t(TP tp) {
14125 using namespace std::chrono;
14126 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14127 4 return system_clock::to_time_t(sctp);
14128 }
14129
14130 4 std::string get_time_last_modified_string(std::string path)
14131 {
14132
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14133 // TODO: C++20 but not supported yet.
14134 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14135 4 std::time_t tt = to_time_t(write_time);
14136 4 std::tm *gmt = std::gmtime(&tt);
14137 4 std::stringstream buffer;
14138
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14139
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14140 4 return formattedFileTime;
14141
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14142
14143 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14144 {
14145 // Always backup quest if it was last saved in a different version of the editor,
14146 // or if this a new file and is overwritting another qst file.
14147
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14148 {
14149 4 std::string backup_name;
14150
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14151
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14152 {
14153
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14154 4 }
14155 else
14156 {
14157 backup_name = fmt::format("{}", last_mod);
14158 }
14159
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14160
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14161
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14162 {
14163
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14164
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14165 {
14166
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14167 4 }
14168 else
14169 {
14170 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14171 }
14172 4 }
14173 4 }
14174
14175 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14176 6 fake_pack_writing = false;
14177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14178 {
14179 box_out("-- Error saving quest file! --");
14180 box_end(true);
14181 }
14182 6 else box_end(false);
14183 6 return ret;
14184 }
14185
14186 6 int32_t save_quest(const char *filename, bool timed_save)
14187 {
14188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14189
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14190 char ext1[5];
14191 6 ext1[0]=0;
14192
14193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14194 {
14195 sprintf(ext1, "qt");
14196 }
14197 else
14198 {
14199 6 sprintf(ext1, "qb");
14200 }
14201
14202
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14203 {
14204 char backupname[2048];
14205 char backupname2[2048];
14206 char ext[12];
14207
14208 for(int32_t i=retention-1; i>0; --i)
14209 {
14210 sprintf(ext, "%s%d", ext1, i-1);
14211 replace_extension(backupname, filepath, ext, 2047);
14212
14213 if(exists(backupname))
14214 {
14215 sprintf(ext, "%s%d", ext1, i);
14216 replace_extension(backupname2, filepath, ext, 2047);
14217
14218 if(exists(backupname2))
14219 {
14220 remove(backupname2);
14221 }
14222
14223 rename(backupname, backupname2);
14224 }
14225 }
14226
14227 //don't do this if we're not saving to the same name -DD
14228 if(!timed_save && !strcmp(filepath, filename))
14229 {
14230 sprintf(ext, "%s%d", ext1, 0);
14231 replace_extension(backupname, filepath, ext, 2047);
14232 rename(filepath, backupname);
14233 }
14234 }
14235
14236 int32_t ret;
14237 6 ret = save_unencoded_quest(filename, compress, filename);
14238
14239 6 return ret;
14240 }
14241
14242 6 void center_zq_class_dialogs()
14243 {
14244 6 jwin_center_dialog(pwd_dlg);
14245 6 }
14246
14247 void zmap::prv_secrets(bool high16only)
14248 {
14249 mapscr *s = &prvscr;
14250 mapscr *t = prvlayers;
14251 int32_t ft=0;
14252
14253 for(int32_t i=0; i<176; i++)
14254 {
14255 bool putit;
14256
14257 if(!high16only)
14258 {
14259 for(int32_t j=-1; j<6; j++)
14260 {
14261 int32_t newflag = -1;
14262
14263 for(int32_t iter=0; iter<2; ++iter)
14264 {
14265 putit=true;
14266
14267 if(!t[j].valid)
14268 continue;
14269
14270 int32_t checkflag=combobuf[t[j].data[i]].flag;
14271
14272 if(iter==1)
14273 {
14274 checkflag=t[j].sflag[i];
14275 }
14276
14277 switch(checkflag)
14278 {
14279 case mfANYFIRE:
14280 ft=sBCANDLE;
14281 break;
14282
14283 case mfSTRONGFIRE:
14284 ft=sRCANDLE;
14285 break;
14286
14287 case mfMAGICFIRE:
14288 ft=sWANDFIRE;
14289 break;
14290
14291 case mfDIVINEFIRE:
14292 ft=sDIVINEFIRE;
14293 break;
14294
14295 case mfARROW:
14296 ft=sARROW;
14297 break;
14298
14299 case mfSARROW:
14300 ft=sSARROW;
14301 break;
14302
14303 case mfGARROW:
14304 ft=sGARROW;
14305 break;
14306
14307 case mfSBOMB:
14308 ft=sSBOMB;
14309 break;
14310
14311 case mfBOMB:
14312 ft=sBOMB;
14313 break;
14314
14315 case mfBRANG:
14316 ft=sBRANG;
14317 break;
14318
14319 case mfMBRANG:
14320 ft=sMBRANG;
14321 break;
14322
14323 case mfFBRANG:
14324 ft=sFBRANG;
14325 break;
14326
14327 case mfWANDMAGIC:
14328 ft=sWANDMAGIC;
14329 break;
14330
14331 case mfREFMAGIC:
14332 ft=sREFMAGIC;
14333 break;
14334
14335 case mfREFFIREBALL:
14336 ft=sREFFIREBALL;
14337 break;
14338
14339 case mfSWORD:
14340 ft=sSWORD;
14341 break;
14342
14343 case mfWSWORD:
14344 ft=sWSWORD;
14345 break;
14346
14347 case mfMSWORD:
14348 ft=sMSWORD;
14349 break;
14350
14351 case mfXSWORD:
14352 ft=sXSWORD;
14353 break;
14354
14355 case mfSWORDBEAM:
14356 ft=sSWORDBEAM;
14357 break;
14358
14359 case mfWSWORDBEAM:
14360 ft=sWSWORDBEAM;
14361 break;
14362
14363 case mfMSWORDBEAM:
14364 ft=sMSWORDBEAM;
14365 break;
14366
14367 case mfXSWORDBEAM:
14368 ft=sXSWORDBEAM;
14369 break;
14370
14371 case mfHOOKSHOT:
14372 ft=sHOOKSHOT;
14373 break;
14374
14375 case mfWAND:
14376 ft=sWAND;
14377 break;
14378
14379 case mfHAMMER:
14380 ft=sHAMMER;
14381 break;
14382
14383 case mfSTRIKE:
14384 ft=sSTRIKE;
14385 break;
14386
14387 default:
14388 putit = false;
14389 break;
14390 }
14391
14392 if(putit)
14393 {
14394 if(j==-1)
14395 {
14396 s->data[i] = s->secretcombo[ft];
14397 s->cset[i] = s->secretcset[ft];
14398 newflag = s->secretflag[ft];
14399 }
14400 else
14401 {
14402 t[j].data[i] = t[j].secretcombo[ft];
14403 t[j].cset[i] = t[j].secretcset[ft];
14404 newflag = t[j].secretflag[ft];
14405 }
14406 }
14407 }
14408
14409 if(newflag >-1)
14410 {
14411 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14412 }
14413 }
14414 }
14415
14416 //if(true)
14417 //{
14418 int32_t newflag = -1;
14419
14420 for(int32_t iter=0; iter<2; ++iter)
14421 {
14422 int32_t checkflag=combobuf[s->data[i]].flag;
14423
14424 if(iter==1)
14425 {
14426 checkflag=s->sflag[i];
14427 }
14428
14429 if((checkflag > 15)&&(checkflag < 32))
14430 {
14431 s->data[i] = s->secretcombo[(checkflag)-16+4];
14432 s->cset[i] = s->secretcset[(checkflag)-16+4];
14433 newflag = s->secretflag[(checkflag)-16+4];
14434 // putit = true;
14435 }
14436 }
14437
14438 if(newflag >-1) s->sflag[i] = newflag;
14439
14440 for(int32_t j=0; j<6; j++)
14441 {
14442 if(!t[j].valid) continue;
14443
14444 int32_t newflag2 = -1;
14445
14446 for(int32_t iter=0; iter<2; ++iter)
14447 {
14448 int32_t checkflag=combobuf[t[j].data[i]].flag;
14449
14450 if(iter==1)
14451 {
14452 checkflag=t[j].sflag[i];
14453 }
14454
14455 if((checkflag > 15)&&(checkflag < 32))
14456 {
14457 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14458 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14459 newflag2 = t[j].secretflag[(checkflag)-16+4];
14460 }
14461 }
14462
14463 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14464 }
14465 }
14466
14467 //FFCs
14468 word c = s->numFFC();
14469 for(word i=0; i<c; ++i)
14470 {
14471 bool putit;
14472
14473 if(!high16only)
14474 {
14475 for(int32_t iter=0; iter<1; ++iter)
14476 {
14477 putit=true;
14478 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14479
14480 if(iter==1)
14481 {
14482 checkflag=s->sflag[i];
14483 }
14484
14485 switch(checkflag)
14486 {
14487 case mfANYFIRE:
14488 ft=sBCANDLE;
14489 break;
14490
14491 case mfSTRONGFIRE:
14492 ft=sRCANDLE;
14493 break;
14494
14495 case mfMAGICFIRE:
14496 ft=sWANDFIRE;
14497 break;
14498
14499 case mfDIVINEFIRE:
14500 ft=sDIVINEFIRE;
14501 break;
14502
14503 case mfARROW:
14504 ft=sARROW;
14505 break;
14506
14507 case mfSARROW:
14508 ft=sSARROW;
14509 break;
14510
14511 case mfGARROW:
14512 ft=sGARROW;
14513 break;
14514
14515 case mfSBOMB:
14516 ft=sSBOMB;
14517 break;
14518
14519 case mfBOMB:
14520 ft=sBOMB;
14521 break;
14522
14523 case mfBRANG:
14524 ft=sBRANG;
14525 break;
14526
14527 case mfMBRANG:
14528 ft=sMBRANG;
14529 break;
14530
14531 case mfFBRANG:
14532 ft=sFBRANG;
14533 break;
14534
14535 case mfWANDMAGIC:
14536 ft=sWANDMAGIC;
14537 break;
14538
14539 case mfREFMAGIC:
14540 ft=sREFMAGIC;
14541 break;
14542
14543 case mfREFFIREBALL:
14544 ft=sREFFIREBALL;
14545 break;
14546
14547 case mfSWORD:
14548 ft=sSWORD;
14549 break;
14550
14551 case mfWSWORD:
14552 ft=sWSWORD;
14553 break;
14554
14555 case mfMSWORD:
14556 ft=sMSWORD;
14557 break;
14558
14559 case mfXSWORD:
14560 ft=sXSWORD;
14561 break;
14562
14563 case mfSWORDBEAM:
14564 ft=sSWORDBEAM;
14565 break;
14566
14567 case mfWSWORDBEAM:
14568 ft=sWSWORDBEAM;
14569 break;
14570
14571 case mfMSWORDBEAM:
14572 ft=sMSWORDBEAM;
14573 break;
14574
14575 case mfXSWORDBEAM:
14576 ft=sXSWORDBEAM;
14577 break;
14578
14579 case mfHOOKSHOT:
14580 ft=sHOOKSHOT;
14581 break;
14582
14583 case mfWAND:
14584 ft=sWAND;
14585 break;
14586
14587 case mfHAMMER:
14588 ft=sHAMMER;
14589 break;
14590
14591 case mfSTRIKE:
14592 ft=sSTRIKE;
14593 break;
14594
14595 default:
14596 putit = false;
14597 break;
14598 }
14599
14600 if(putit)
14601 {
14602 s->ffcs[i].data = s->secretcombo[ft];
14603 s->ffcs[i].cset = s->secretcset[ft];
14604 }
14605 }
14606 }
14607
14608 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14609 {
14610 for(int32_t iter=0; iter<1; ++iter)
14611 {
14612 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14613
14614 if(iter==1)
14615 {
14616 // FFCs can't have flags! Yet...
14617 }
14618
14619 if((checkflag > 15)&&(checkflag < 32))
14620 {
14621 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14622 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14623 }
14624 }
14625 }
14626 }
14627 }
14628